AACRtmp.h 2.07 KB
Newer Older
1
/*
xiongziliang committed
2
 * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
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.
9
 */
10 11 12 13

#ifndef ZLMEDIAKIT_AACRTMPCODEC_H
#define ZLMEDIAKIT_AACRTMPCODEC_H

xiongziliang committed
14
#include "Rtmp/RtmpCodec.h"
15 16
#include "Extension/Track.h"
#include "Extension/AAC.h"
17

xiongziliang committed
18
namespace mediakit{
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
/**
 * aac Rtmp转adts类
 */
class AACRtmpDecoder : public RtmpCodec , public ResourcePoolHelper<AACFrame> {
public:
    typedef std::shared_ptr<AACRtmpDecoder> Ptr;

    AACRtmpDecoder();
    ~AACRtmpDecoder() {}

    /**
     * 输入Rtmp并解码
     * @param Rtmp Rtmp数据包
     * @param key_pos 此参数内部强制转换为false,请忽略之
     */
    bool inputRtmp(const RtmpPacket::Ptr &Rtmp, bool key_pos = false) override;

    CodecId getCodecId() const override{
        return CodecAAC;
    }

protected:
xiongziliang committed
41
    void onGetAAC(const char* data, int len, uint32_t stamp);
42 43 44 45 46 47 48 49 50 51 52 53 54 55
    AACFrame::Ptr obtainFrame();
protected:
    AACFrame::Ptr _adts;
    string _aac_cfg;
};


/**
 * aac adts转Rtmp类
 */
class AACRtmpEncoder : public AACRtmpDecoder ,  public ResourcePoolHelper<RtmpPacket> {
public:
    typedef std::shared_ptr<AACRtmpEncoder> Ptr;

56 57 58 59 60 61 62
    /**
     * 构造函数,track可以为空,此时则在inputFrame时输入adts头
     * 如果track不为空且包含adts头相关信息,
     * 那么inputFrame时可以不输入adts头
     * @param track
     */
    AACRtmpEncoder(const Track::Ptr &track);
63 64 65
    ~AACRtmpEncoder() {}

    /**
66 67
     * 输入aac 数据,可以不带adts头
     * @param frame aac数据
68 69 70
     */
    void inputFrame(const Frame::Ptr &frame) override;

71 72 73 74
    /**
     * 生成config包
     */
    void makeConfigPacket() override;
75 76
private:
    void makeAudioConfigPkt();
77
private:
xiongziliang committed
78
    uint8_t _audio_flv_flags;
79
    AACTrack::Ptr _track;
80 81
};

xiongziliang committed
82
}//namespace mediakit
83 84

#endif //ZLMEDIAKIT_AACRTMPCODEC_H