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
|
|
|
|
|
2022-02-02 20:34:50 +08:00
|
|
|
|
using namespace std;
|
|
|
|
|
using namespace toolkit;
|
|
|
|
|
|
|
|
|
|
namespace mediakit {
|
2018-10-24 14:21:59 +08:00
|
|
|
|
|
2020-09-06 18:22:04 +08:00
|
|
|
|
void AACRtmpDecoder::inputRtmp(const RtmpPacket::Ptr &pkt) {
|
2024-03-22 20:37:27 +08:00
|
|
|
|
CHECK_RET(pkt->size() > 2);
|
2023-07-22 19:40:28 +08:00
|
|
|
|
if (pkt->isConfigFrame()) {
|
2023-12-09 16:23:51 +08:00
|
|
|
|
getTrack()->setExtraData((uint8_t *)pkt->data() + 2, pkt->size() - 2);
|
2020-09-06 18:22:04 +08:00
|
|
|
|
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
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2021-09-27 13:12:53 +08:00
|
|
|
|
bool AACRtmpEncoder::inputFrame(const Frame::Ptr &frame) {
|
2023-07-22 18:54:59 +08:00
|
|
|
|
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);
|
2021-09-27 13:12:53 +08:00
|
|
|
|
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());
|
2023-07-22 18:54:59 +08:00
|
|
|
|
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
|
|
|
|
|
2023-07-22 18:54:59 +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());
|
|
|
|
|
|
2023-07-22 18:54:59 +08:00
|
|
|
|
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
|