MediaRecorder.cpp 3.57 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"
xzl committed
33 34 35 36 37 38 39

using namespace ZL::Util;
using namespace ZL::Network;

namespace ZL {
namespace MediaFile {

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

47 48 49 50
    GET_CONFIG_AND_REGISTER(string,hlsPath,Config::Hls::kFilePath);
    GET_CONFIG_AND_REGISTER(uint32_t,hlsBufSize,Config::Hls::kFileBufSize);
    GET_CONFIG_AND_REGISTER(uint32_t,hlsDuration,Config::Hls::kSegmentDuration);
    GET_CONFIG_AND_REGISTER(uint32_t,hlsNum,Config::Hls::kSegmentNum);
xzl committed
51

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

    if(enableHls) {
59 60
        auto m3u8FilePath = hlsPath + "/" + strVhost + "/" + strApp + "/" + strId + "/hls.m3u8";
        m_hlsMaker.reset(new HLSMaker(m3u8FilePath,hlsBufSize, hlsDuration, hlsNum));
61
    }
62

63
#ifdef ENABLE_MP4V2
64 65 66
    GET_CONFIG_AND_REGISTER(string,recordPath,Config::Record::kFilePath);
    GET_CONFIG_AND_REGISTER(string,recordAppName,Config::Record::kAppName);

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

MediaRecorder::~MediaRecorder() {
}

void MediaRecorder::inputH264(void* pData, uint32_t ui32Length, uint32_t ui32TimeStamp, int iType) {
78
    if(m_hlsMaker){
xiongziliang committed
79
        m_hlsMaker->inputH264(pData, ui32Length, ui32TimeStamp, iType);
80
    }
81
#ifdef ENABLE_MP4V2
82 83 84
    if(m_mp4Maker){
        m_mp4Maker->inputH264(pData, ui32Length, ui32TimeStamp, iType);
    }
85
#endif //ENABLE_MP4V2
xzl committed
86 87 88
}

void MediaRecorder::inputAAC(void* pData, uint32_t ui32Length, uint32_t ui32TimeStamp) {
89
    if(m_hlsMaker){
xiongziliang committed
90
        m_hlsMaker->inputAAC(pData, ui32Length, ui32TimeStamp);
91
    }
92
#ifdef ENABLE_MP4V2
93 94 95
    if(m_mp4Maker){
        m_mp4Maker->inputAAC(pData, ui32Length, ui32TimeStamp);
    }
96
#endif //ENABLE_MP4V2
xzl committed
97 98 99 100
}

} /* namespace MediaFile */
} /* namespace ZL */