ZLMediaKit/ext-codec/AACRtmp.cpp

66 lines
2.1 KiB
C++
Raw Normal View History

2018-10-25 10:00:17 +08:00
/*
2023-12-09 16:23:51 +08:00
* Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
2018-10-25 10:00:17 +08:00
*
2023-12-09 16:23:51 +08:00
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
2018-10-25 10:00:17 +08:00
*
2023-12-09 16:23:51 +08:00
* Use of this source code is governed by MIT-like license that can be found in the
2020-04-04 20:30:09 +08:00
* 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.
2018-10-25 10:00:17 +08:00
*/
2020-04-04 20:30:09 +08:00
2019-06-28 17:37:11 +08:00
#include "AACRtmp.h"
2020-04-04 22:54:49 +08:00
#include "Rtmp/Rtmp.h"
2018-10-24 14:21:59 +08:00
using namespace std;
using namespace toolkit;
namespace mediakit {
2018-10-24 14:21:59 +08:00
void AACRtmpDecoder::inputRtmp(const RtmpPacket::Ptr &pkt) {
2023-12-09 16:23:51 +08:00
CHECK(pkt->size() > 2);
if (pkt->isConfigFrame()) {
2023-12-09 16:23:51 +08:00
getTrack()->setExtraData((uint8_t *)pkt->data() + 2, pkt->size() - 2);
return;
2018-10-24 14:21:59 +08:00
}
2023-12-09 16:23:51 +08:00
RtmpCodec::inputFrame(std::make_shared<FrameFromPtr>(CodecAAC, pkt->buffer.data() + 2, pkt->buffer.size() - 2, pkt->time_stamp));
2018-10-24 14:21:59 +08:00
}
2020-05-11 23:25:12 +08:00
2018-10-24 14:21:59 +08:00
/////////////////////////////////////////////////////////////////////////////////////
bool AACRtmpEncoder::inputFrame(const Frame::Ptr &frame) {
auto pkt = RtmpPacket::create();
// header
pkt->buffer.push_back(_audio_flv_flags);
pkt->buffer.push_back((uint8_t)RtmpAACPacketType::aac_raw);
// aac data
pkt->buffer.append(frame->data() + frame->prefixSize(), frame->size() - frame->prefixSize());
pkt->body_size = pkt->buffer.size();
pkt->chunk_id = CHUNK_AUDIO;
pkt->stream_index = STREAM_MEDIA;
pkt->time_stamp = frame->dts();
pkt->type_id = MSG_AUDIO;
RtmpCodec::inputRtmp(pkt);
return true;
2018-10-24 14:21:59 +08:00
}
2023-12-09 16:23:51 +08:00
void AACRtmpEncoder::makeConfigPacket() {
_audio_flv_flags = getAudioRtmpFlags(getTrack());
auto pkt = RtmpPacket::create();
// header
pkt->buffer.push_back(_audio_flv_flags);
pkt->buffer.push_back((uint8_t)RtmpAACPacketType::aac_config_header);
2023-12-09 16:23:51 +08:00
// aac config
2023-12-09 16:23:51 +08:00
auto extra_data = getTrack()->getExtraData();
CHECK(extra_data);
pkt->buffer.append(extra_data->data(), extra_data->size());
pkt->body_size = pkt->buffer.size();
pkt->chunk_id = CHUNK_AUDIO;
pkt->stream_index = STREAM_MEDIA;
pkt->time_stamp = 0;
pkt->type_id = MSG_AUDIO;
RtmpCodec::inputRtmp(pkt);
2018-10-24 14:21:59 +08:00
}
2018-10-24 17:17:55 +08:00
}//namespace mediakit