MP4Recorder.h 2.04 KB
Newer Older
xiongziliang committed
1 2
/*
 * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
xiongziliang committed
3 4 5
 *
 * This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
 *
xiongziliang committed
6 7 8
 * Use of this source code is governed by MIT license that can be found in the
 * LICENSE file in the root of the source tree. All contributing project authors
 * may be found in the AUTHORS file in the root of the source tree.
xzl committed
9 10 11 12 13 14 15
 */

#ifndef MP4MAKER_H_
#define MP4MAKER_H_

#include <mutex>
#include <memory>
xiongzilaing committed
16
#include "Player/PlayerBase.h"
xzl committed
17
#include "Util/util.h"
xiongzilaing committed
18
#include "Util/logger.h"
xzl committed
19 20
#include "Util/TimeTicker.h"
#include "Util/TimeTicker.h"
21
#include "Common/MediaSink.h"
xiongziliang committed
22
#include "MP4Muxer.h"
xiongziliang committed
23
using namespace toolkit;
xzl committed
24

xiongziliang committed
25
namespace mediakit {
xzl committed
26

27
class MP4Info {
xzl committed
28
public:
29 30 31 32 33 34 35 36 37 38
    time_t ui64StartedTime; //GMT标准时间,单位秒
    time_t ui64TimeLen;//录像长度,单位秒
    off_t ui64FileSize;//文件大小,单位BYTE
    string strFilePath;//文件路径
    string strFileName;//文件名称
    string strFolder;//文件夹路径
    string strUrl;//播放路径
    string strAppName;//应用名称
    string strStreamId;//流ID
    string strVhost;//vhost
xzl committed
39
};
40

xiongziliang committed
41
#ifdef ENABLE_MP4
xiongziliang committed
42
class MP4Recorder : public MediaSinkInterface{
xzl committed
43
public:
44
    typedef std::shared_ptr<MP4Recorder> Ptr;
45

46 47 48 49 50
    MP4Recorder(const string &strPath,
                const string &strVhost,
                const string &strApp,
                const string &strStreamId);
    virtual ~MP4Recorder();
51

52 53 54 55
    /**
     * 重置所有Track
     */
    void resetTracks() override;
xiongziliang committed
56

57
    /**
xiongziliang committed
58
     * 输入frame
59
     */
60
    void inputFrame(const Frame::Ptr &frame) override;
61

xiongziliang committed
62
    /**
xiongziliang committed
63
     * 添加ready状态的track
xiongziliang committed
64
     */
xiongziliang committed
65
    void addTrack(const Track::Ptr & track) override;
66 67 68
private:
    void createFile();
    void closeFile();
69
    void asyncClose();
xzl committed
70
private:
71 72 73 74 75 76
    string _strPath;
    string _strFile;
    string _strFileTmp;
    Ticker _createFileTicker;
    MP4Info _info;
    bool _haveVideo = false;
xiongziliang committed
77
    MP4Muxer::Ptr _muxer;
78
    list<Track::Ptr> _tracks;
xzl committed
79 80
};

xiongziliang committed
81
#endif ///ENABLE_MP4
xzl committed
82

83 84
} /* namespace mediakit */

xzl committed
85
#endif /* MP4MAKER_H_ */