fixed build issue

This commit is contained in:
cqm 2024-07-12 10:35:17 +08:00
parent 2ffdfab71e
commit e6838f24af
3 changed files with 31 additions and 78 deletions

View File

@ -18,17 +18,16 @@
#include <float.h> #include <float.h>
#include "Transcode.h" #include "Transcode.h"
#include "Common/config.h" #include "Common/config.h"
#include "Extension/Opus.h" #include "Extension/Factory.h"
#include "Extension/G711.h"
#include "Extension/H264.h"
#include "Extension/H265.h"
#define ADTS_HEADER_LEN 7
#define MAX_DELAY_SECOND 3 #define MAX_DELAY_SECOND 3
using namespace std; using namespace std;
using namespace toolkit; using namespace toolkit;
namespace mediakit { namespace mediakit {
extern int dumpAacConfig(const string &config, size_t length, uint8_t *out, size_t out_size);
static string ffmpeg_err(int errnum) { static string ffmpeg_err(int errnum) {
char errbuf[AV_ERROR_MAX_STRING_SIZE]; char errbuf[AV_ERROR_MAX_STRING_SIZE];
@ -1045,26 +1044,7 @@ void FFmpegEncoder::onEncode(AVPacket *packet) {
// process frame // process frame
if (!_cb) if (!_cb)
return; return;
switch (_codecId) { if (_codecId == CodecAAC) {
case CodecH264: {
auto frame = FrameImp::create<H264Frame>();
frame->_dts = packet->dts;
frame->_pts = packet->pts;
frame->_buffer.assign((const char *)packet->data, packet->size);
frame->_prefix_size = prefixSize((const char *)packet->data, packet->size);
_cb(frame);
break;
}
case CodecH265: {
auto frame = FrameImp::create<H265Frame>();
frame->_dts = packet->dts;
frame->_pts = packet->pts;
frame->_buffer.assign((const char *)packet->data, packet->size);
frame->_prefix_size = prefixSize((const char *)packet->data, packet->size);
_cb(frame);
break;
}
case CodecAAC: {
auto frame = FrameImp::create<>(); auto frame = FrameImp::create<>();
frame->_codec_id = _codecId; frame->_codec_id = _codecId;
frame->_dts = packet->dts; frame->_dts = packet->dts;
@ -1079,30 +1059,8 @@ void FFmpegEncoder::onEncode(AVPacket *packet) {
} }
frame->_buffer.append((const char *)packet->data, packet->size); frame->_buffer.append((const char *)packet->data, packet->size);
_cb(frame); _cb(frame);
break; } else {
} _cb(Factory::getFrameFromPtr(_codecId, (const char*)packet->data, packet->size, packet->dts, packet->pts));
case CodecOpus:
case CodecG711A:
case CodecG711U: {
auto frame = FrameImp::create<>();
frame->_codec_id = _codecId;
frame->_dts = packet->dts;
frame->_pts = packet->pts;
frame->_buffer.assign((const char *)packet->data, packet->size);
_cb(frame);
break;
}
case CodecVP8:
case CodecVP9: {
auto frame = FrameImp::create<>();
frame->_codec_id = _codecId;
frame->_dts = packet->dts;
frame->_pts = packet->pts;
frame->_buffer.assign((const char *)packet->data, packet->size);
_cb(frame);
break;
}
default: break;
} }
} }

View File

@ -1,34 +1,35 @@
#include "Codec/Transcode.h" #include "Codec/Transcode.h"
#include "Record/MP4Demuxer.h" #include "Record/MP4Demuxer.h"
#include "Record/MP4Muxer.h" #include "Record/MP4Muxer.h"
#include "Extension/AAC.h"
#include "Extension/Opus.h"
#include "Extension/G711.h"
#include "Util/logger.h" #include "Util/logger.h"
using namespace mediakit; using namespace mediakit;
struct TransCtx { struct TransCtx {
using Ptr = std::shared_ptr<TransCtx>; using Ptr = std::shared_ptr<TransCtx>;
TransCtx(const char *prefix, CodecId codec) { TransCtx(const char *prefix, CodecId codec) {
char path[256]; char path[256];
Track::Ptr track; int samplerate;
int channel = 1;
int bits = 16;
switch (codec) { switch (codec) {
case CodecAAC: case CodecAAC:
track.reset(new AACTrack(44100, 1)); samplerate = 44100;
sprintf(path, "%s_aac.mp4", prefix); sprintf(path, "%s_aac.mp4", prefix);
break; break;
case CodecOpus: case CodecOpus:
track.reset(new OpusTrack()); samplerate = 48000;
sprintf(path, "%s_opus.mp4", prefix); sprintf(path, "%s_opus.mp4", prefix);
break; break;
case CodecG711A: case CodecG711A:
case CodecG711U: case CodecG711U:
track.reset(new G711Track(codec, 8000, 1, 16)); samplerate = 8000;
sprintf(path, "%s_711%c.mp4", prefix, codec == CodecG711A ? 'A' : 'U'); sprintf(path, "%s_711%c.mp4", prefix, codec == CodecG711A ? 'A' : 'U');
break; break;
default: default:
return; return;
break; break;
} }
Track::Ptr track = std::make_shared<AudioTrackImp>(codec, samplerate, channel, bits);
file.reset(new MP4Muxer()); file.reset(new MP4Muxer());
file->openMP4(path); file->openMP4(path);
file->addTrack(track); file->addTrack(track);

View File

@ -68,17 +68,11 @@ bool RtcMediaSourceMuxer::inputFrame(const Frame::Ptr &frame)
switch (frame->getCodecId()) switch (frame->getCodecId())
{ {
case CodecAAC: case CodecAAC:
if (frame->prefixSize()) { track = Factory::getTrackByCodecId(CodecAAC, 44100, 2, 16);
std::string cfg = makeAacConfig((uint8_t *)(frame->data()), frame->prefixSize());
track = std::make_shared<AACTrack>(cfg);
}
else {
track = std::make_shared<AACTrack>(44100, 2);
}
break; break;
case CodecG711A: case CodecG711A:
case CodecG711U: case CodecG711U:
track.reset(new G711Track(frame->getCodecId())); track = Factory::getTrackByCodecId(frame->getCodecId());
break; break;
default: default:
break; break;
@ -116,7 +110,7 @@ bool RtcMediaSourceMuxer::addTrack(const Track::Ptr & track)
{ {
Track::Ptr newTrack = track; Track::Ptr newTrack = track;
if (_option.audio_transcode && needTransToOpus(track->getCodecId())) { if (_option.audio_transcode && needTransToOpus(track->getCodecId())) {
newTrack = std::make_shared<OpusTrack>(); newTrack = Factory::getTrackByCodecId(CodecOpus);
GET_CONFIG(int, bitrate, General::kOpusBitrate); GET_CONFIG(int, bitrate, General::kOpusBitrate);
newTrack->setBitRate(bitrate); newTrack->setBitRate(bitrate);
_audio_dec.reset(new FFmpegDecoder(track)); _audio_dec.reset(new FFmpegDecoder(track));
@ -149,7 +143,7 @@ bool RtcMediaSourceImp::addTrack(const Track::Ptr &track)
if (_muxer) { if (_muxer) {
Track::Ptr newTrack = track; Track::Ptr newTrack = track;
if (_option.audio_transcode && needTransToAac(track->getCodecId())) { if (_option.audio_transcode && needTransToAac(track->getCodecId())) {
newTrack.reset(new AACTrack(44100, 2)); newTrack = Factory::getTrackByCodecId(CodecAAC, 44100, std::dynamic_pointer_cast<AudioTrack>(track)->getAudioChannel(), 16);
GET_CONFIG(int, bitrate, General::kAacBitrate); GET_CONFIG(int, bitrate, General::kAacBitrate);
newTrack->setBitRate(bitrate); newTrack->setBitRate(bitrate);
_audio_dec.reset(new FFmpegDecoder(track)); _audio_dec.reset(new FFmpegDecoder(track));