Files
ZLMediaKit/src/Extension/CommonRtmp.cpp

43 lines
1.4 KiB
C++
Raw Normal View History

2020-08-01 10:24:28 +08:00
/*
2023-12-09 16:23:51 +08:00
* Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
2020-08-01 10:22:12 +08:00
*
2023-12-09 16:23:51 +08:00
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
2020-08-01 10:22:12 +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-08-01 10:22:12 +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.
*/
#include "CommonRtmp.h"
2023-12-09 16:23:51 +08:00
namespace mediakit {
2020-08-01 10:22:12 +08:00
void CommonRtmpDecoder::inputRtmp(const RtmpPacket::Ptr &rtmp) {
2023-12-09 16:23:51 +08:00
auto frame = FrameImp::create();
frame->_codec_id = getTrack()->getCodecId();
frame->_buffer.assign(rtmp->buffer.data() + 1, rtmp->buffer.size() - 1);
frame->_dts = rtmp->time_stamp;
RtmpCodec::inputFrame(frame);
2020-08-01 10:22:12 +08:00
}
/////////////////////////////////////////////////////////////////////////////////////
bool CommonRtmpEncoder::inputFrame(const Frame::Ptr &frame) {
2020-08-01 10:22:12 +08:00
if (!_audio_flv_flags) {
2023-12-09 16:23:51 +08:00
_audio_flv_flags = getAudioRtmpFlags(getTrack());
2020-08-01 10:22:12 +08:00
}
2021-02-04 17:58:51 +08:00
auto rtmp = RtmpPacket::create();
2023-12-09 16:23:51 +08:00
// header
2020-08-30 10:48:34 +08:00
rtmp->buffer.push_back(_audio_flv_flags);
2023-12-09 16:23:51 +08:00
// data
2020-08-30 10:48:34 +08:00
rtmp->buffer.append(frame->data() + frame->prefixSize(), frame->size() - frame->prefixSize());
rtmp->body_size = rtmp->buffer.size();
rtmp->chunk_id = CHUNK_AUDIO;
rtmp->stream_index = STREAM_MEDIA;
rtmp->time_stamp = frame->dts();
rtmp->type_id = MSG_AUDIO;
RtmpCodec::inputRtmp(rtmp);
return true;
2020-08-01 10:22:12 +08:00
}
}//namespace mediakit