MediaRecorder.cpp 3.45 KB
Newer Older
xiongziliang committed
1
/*
xiongziliang committed
2
 * MIT License
xzl committed
3
 *
xiongziliang committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 * Copyright (c) 2016 xiongziliang <771730766@qq.com>
 *
 * This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
xzl committed
25 26 27
 */

#include "MediaRecorder.h"
xiongziliang committed
28
#include "Common/config.h"
xzl committed
29
#include "Http/HttpSession.h"
xiongzilaing committed
30 31 32
#include "Util/util.h"
#include "Util/mini.h"
#include "Network/sockutil.h"
xiongziliang committed
33
using namespace toolkit;
xzl committed
34

xiongziliang committed
35
namespace mediakit {
xzl committed
36

37 38 39 40 41 42 43
MediaRecorder::MediaRecorder(const string &strVhost_tmp,
                             const string &strApp,
                             const string &strId,
                             const std::shared_ptr<PlayerBase> &pPlayer,
                             bool enableHls,
                             bool enableMp4) {

xiongziliang committed
44 45 46 47
    GET_CONFIG_AND_REGISTER(string,hlsPath,Hls::kFilePath);
    GET_CONFIG_AND_REGISTER(uint32_t,hlsBufSize,Hls::kFileBufSize);
    GET_CONFIG_AND_REGISTER(uint32_t,hlsDuration,Hls::kSegmentDuration);
    GET_CONFIG_AND_REGISTER(uint32_t,hlsNum,Hls::kSegmentNum);
xzl committed
48

49 50 51 52 53 54 55
    string strVhost = strVhost_tmp;
    if(trim(strVhost).empty()){
        //如果strVhost为空,则强制为默认虚拟主机
        strVhost = DEFAULT_VHOST;
    }

    if(enableHls) {
56
        auto m3u8FilePath = hlsPath + "/" + strVhost + "/" + strApp + "/" + strId + "/hls.m3u8";
57
        _hlsMaker.reset(new HLSMaker(m3u8FilePath,hlsBufSize, hlsDuration, hlsNum));
58
    }
59

60
#ifdef ENABLE_MP4V2
xiongziliang committed
61 62
    GET_CONFIG_AND_REGISTER(string,recordPath,Record::kFilePath);
    GET_CONFIG_AND_REGISTER(string,recordAppName,Record::kAppName);
63

64
    if(enableMp4){
65
        auto mp4FilePath = recordPath + "/" + strVhost + "/" + recordAppName + "/" + strApp + "/"  + strId + "/";
66
        _mp4Maker.reset(new Mp4Maker(mp4FilePath,strVhost,strApp,strId,pPlayer));
67
    }
68
#endif //ENABLE_MP4V2
xzl committed
69 70 71 72 73 74
}

MediaRecorder::~MediaRecorder() {
}

void MediaRecorder::inputH264(void* pData, uint32_t ui32Length, uint32_t ui32TimeStamp, int iType) {
75 76
    if(_hlsMaker){
        _hlsMaker->inputH264(pData, ui32Length, ui32TimeStamp, iType);
77
    }
78
#ifdef ENABLE_MP4V2
79 80
    if(_mp4Maker){
        _mp4Maker->inputH264(pData, ui32Length, ui32TimeStamp, iType);
81
    }
82
#endif //ENABLE_MP4V2
xzl committed
83 84 85
}

void MediaRecorder::inputAAC(void* pData, uint32_t ui32Length, uint32_t ui32TimeStamp) {
86 87
    if(_hlsMaker){
        _hlsMaker->inputAAC(pData, ui32Length, ui32TimeStamp);
88
    }
89
#ifdef ENABLE_MP4V2
90 91
    if(_mp4Maker){
        _mp4Maker->inputAAC(pData, ui32Length, ui32TimeStamp);
92
    }
93
#endif //ENABLE_MP4V2
xzl committed
94 95
}

xiongziliang committed
96
} /* namespace mediakit */