MP4Recorder.h 1.62 KB
Newer Older
xiongziliang committed
1 2
/*
 * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
xiongziliang committed
3
 *
4
 * This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
xiongziliang committed
5
 *
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"
23

xiongziliang committed
24
using namespace toolkit;
xzl committed
25

xiongziliang committed
26
namespace mediakit {
xzl committed
27

xiongziliang committed
28
#ifdef ENABLE_MP4
xiongziliang committed
29
class MP4Recorder : public MediaSinkInterface{
xzl committed
30
public:
31
    typedef std::shared_ptr<MP4Recorder> Ptr;
32

33 34 35 36 37
    MP4Recorder(const string &strPath,
                const string &strVhost,
                const string &strApp,
                const string &strStreamId);
    virtual ~MP4Recorder();
38

39 40 41 42
    /**
     * 重置所有Track
     */
    void resetTracks() override;
xiongziliang committed
43

44
    /**
xiongziliang committed
45
     * 输入frame
46
     */
47
    void inputFrame(const Frame::Ptr &frame) override;
48

xiongziliang committed
49
    /**
xiongziliang committed
50
     * 添加ready状态的track
xiongziliang committed
51
     */
xiongziliang committed
52
    void addTrack(const Track::Ptr & track) override;
53 54 55
private:
    void createFile();
    void closeFile();
56
    void asyncClose();
xzl committed
57
private:
58 59 60 61
    string _strPath;
    string _strFile;
    string _strFileTmp;
    Ticker _createFileTicker;
62
    RecordInfo _info;
63
    bool _haveVideo = false;
xiongziliang committed
64
    MP4Muxer::Ptr _muxer;
65
    list<Track::Ptr> _tracks;
xzl committed
66 67
};

xiongziliang committed
68
#endif ///ENABLE_MP4
xzl committed
69

70 71
} /* namespace mediakit */

xzl committed
72
#endif /* MP4MAKER_H_ */