Factory.h 3.75 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/*
 * MIT License
 *
 * 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.
 */
26 27 28 29 30

#ifndef ZLMEDIAKIT_FACTORY_H
#define ZLMEDIAKIT_FACTORY_H

#include <string>
31
#include "Rtmp/amf.h"
32
#include "Extension/Track.h"
33
#include "RtspMuxer/RtspSdp.h"
xiongziliang committed
34 35
#include "RtspMuxer/RtpCodec.h"
#include "RtmpMuxer/RtmpCodec.h"
36 37

using namespace std;
xiongziliang committed
38 39 40
using namespace toolkit;

namespace mediakit{
41 42 43

class Factory {
public:
xiongziliang committed
44

45
    /**
xiongziliang committed
46 47 48
     * 根据CodecId获取Track,该Track的ready()状态一般都为false
     * @param codecId 编解码器id
     * @return
49
     */
50 51
    static Track::Ptr getTrackByCodecId(CodecId codecId);

xiongziliang committed
52 53 54 55
    ////////////////////////////////rtsp相关//////////////////////////////////
    /**
     * 根据sdp生成Track对象
     */
xiongziliang committed
56
    static Track::Ptr getTrackBySdp(const SdpTrack::Ptr &track);
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88

    /**
    * 根据Track生成SDP对象
    * @param track 媒体信息
    * @return 返回sdp对象
    */
    static Sdp::Ptr getSdpByTrack(const Track::Ptr &track);


    /**
     * 根据CodecId生成Rtp打包器
     * @param codecId
     * @param ui32Ssrc
     * @param ui32MtuSize
     * @param ui32SampleRate
     * @param ui8PlayloadType
     * @param ui8Interleaved
     * @return
     */
    static RtpCodec::Ptr getRtpEncoderById(CodecId codecId,
                                           uint32_t ui32Ssrc,
                                           uint32_t ui32MtuSize,
                                           uint32_t ui32SampleRate,
                                           uint8_t ui8PlayloadType,
                                           uint8_t ui8Interleaved);

    /**
     * 根据CodecId生成Rtp解包器
     * @param codecId
     * @param ui32SampleRate
     * @return
     */
89
    static RtpCodec::Ptr getRtpDecoderById(CodecId codecId);
xiongziliang committed
90 91


xiongziliang committed
92
    ////////////////////////////////rtmp相关//////////////////////////////////
xiongziliang committed
93

xiongziliang committed
94 95 96 97 98
    /**
     * 根据amf对象获取响应的Track
     * @param amf rtmp metedata中的videocodecid或audiocodecid的值
     * @return
     */
xiongziliang committed
99
    static Track::Ptr getTrackByAmf(const AMFValue &amf);
xiongziliang committed
100 101 102 103 104 105

    /**
     * 根据amf对象获取相应的CodecId
     * @param val rtmp metedata中的videocodecid或audiocodecid的值
     * @return
     */
xiongziliang committed
106
    static CodecId getCodecIdByAmf(const AMFValue &val);
xiongziliang committed
107 108

    /**
109 110
     * 根据Track获取Rtmp的编解码器
     * @param track 媒体描述对象
xiongziliang committed
111 112
     * @return
     */
113
    static RtmpCodec::Ptr getRtmpCodecByTrack(const Track::Ptr &track);
114 115 116 117 118 119 120 121


    /**
     * 根据codecId获取rtmp的codec描述
     * @param codecId
     * @return
     */
    static AMFValue getAmfByCodecId(CodecId codecId);
122 123
};

xiongziliang committed
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141


















xiongziliang committed
142
}//namespace mediakit
143 144

#endif //ZLMEDIAKIT_FACTORY_H