Skip to content

Commit

Permalink
Improved debugging logs for the transcoder.
Browse files Browse the repository at this point in the history
  • Loading branch information
Keukhan committed Dec 3, 2024
1 parent c35c2bb commit ad1739a
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 12 deletions.
43 changes: 35 additions & 8 deletions src/projects/transcoder/filter/filter_fps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ void FilterFps::SetInputFrameRate(double framerate)
_input_framerate = framerate;
}

double FilterFps::GetInputFrameRate() const
{
return _input_framerate;
}

void FilterFps::SetOutputFrameRate(double framerate)
{
if (_next_pts != AV_NOPTS_VALUE)
Expand All @@ -56,7 +61,7 @@ void FilterFps::SetOutputFrameRate(double framerate)
_output_framerate = framerate;
}

double FilterFps::GetOutputFrameRate()
double FilterFps::GetOutputFrameRate() const
{
return _output_framerate;
}
Expand All @@ -66,6 +71,11 @@ void FilterFps::SetSkipFrames(int32_t skip_frames)
_skip_frames = skip_frames;
}

int32_t FilterFps::GetSkipFrames() const
{
return _skip_frames;
}

bool FilterFps::Push(std::shared_ptr<MediaFrame> media_frame)
{
stat_input_frame_count++;
Expand All @@ -79,13 +89,21 @@ bool FilterFps::Push(std::shared_ptr<MediaFrame> media_frame)

// Changed from Timebase PTS to Framerate PTS.
// ex) 1/90000 -> 1/30
int64_t framerate_pts = av_rescale_q_rnd(media_frame->GetPts(),
(AVRational){_input_timebase.GetNum(), _input_timebase.GetDen()},
av_inv_q(av_d2q(_output_framerate, INT_MAX)),
(AVRounding)(AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX));
// ex )1/1000 -> 100/2997
int64_t scaled_pts = av_rescale_q_rnd(media_frame->GetPts(),
(AVRational){_input_timebase.GetNum(), _input_timebase.GetDen()},
av_inv_q(av_d2q(_output_framerate, INT_MAX)),
(AVRounding)(AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX));

// logtd("Push Frame. PTS(%lld) -> PTS(%lld)", media_frame->GetPts(), framerate_pts);
media_frame->SetPts(framerate_pts);
if ((scaled_pts - _last_input_scaled_pts) != 1 && _last_input_scaled_pts != AV_NOPTS_VALUE)
{
logtd("PTS is not continuous. lastPts(%lld/%lld) -> currPts(%lld/%lld)", _last_input_scaled_pts, _last_input_pts, scaled_pts, media_frame->GetPts());
}

_last_input_pts = media_frame->GetPts();
_last_input_scaled_pts = scaled_pts;

media_frame->SetPts(scaled_pts);

if (_next_pts == AV_NOPTS_VALUE)
{
Expand All @@ -94,13 +112,22 @@ bool FilterFps::Push(std::shared_ptr<MediaFrame> media_frame)

_frames.push_back(media_frame);

#if 0
logtd("Push Frame. PTS(%lld) -> PTS(%lld) (%d/%d) -> (%d/%d)",
_last_input_pts, _last_input_scaled_pts,
_input_timebase.GetNum(), _input_timebase.GetDen(),
av_inv_q(av_d2q(_output_framerate, INT_MAX)).num, av_inv_q(av_d2q(_output_framerate, INT_MAX)).den);
#endif

return true;
}

std::shared_ptr<MediaFrame> FilterFps::Pop()
{
while (_frames.size() >= 2)
{
// If the next PTS is less than the PTS of the second frame,
// the first frame is discarded.
if (_frames[1]->GetPts() <= _next_pts)
{
_frames.erase(_frames.begin());
Expand All @@ -109,7 +136,7 @@ std::shared_ptr<MediaFrame> FilterFps::Pop()

_curr_pts = _next_pts;

// Increase the next PTS
// Increase expected PTS to the next frame
_next_pts++;

// Skip Frame
Expand Down
8 changes: 7 additions & 1 deletion src/projects/transcoder/filter/filter_fps.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ class FilterFps

void SetInputTimebase(cmn::Timebase timebase);
void SetInputFrameRate(double framerate);
double GetInputFrameRate() const;
void SetOutputFrameRate(double framerate);
double GetOutputFrameRate();
double GetOutputFrameRate() const;

void SetSkipFrames(int32_t skip_frames);
int32_t GetSkipFrames() const;
void SetMaximumDupulicateFrames(int32_t max_dupulicate_frames);
bool Push(std::shared_ptr<MediaFrame> media_frame);
std::shared_ptr<MediaFrame> Pop();
Expand Down Expand Up @@ -58,4 +61,7 @@ class FilterFps
int64_t stat_skip_frame_count = 0;
int64_t stat_duplicate_frame_count = 0;
int64_t stat_discard_frame_count = 0;

int64_t _last_input_pts = AV_NOPTS_VALUE;
int64_t _last_input_scaled_pts = AV_NOPTS_VALUE;
};
7 changes: 7 additions & 0 deletions src/projects/transcoder/transcoder_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ class MediaFrame
void SetNbSamples(int32_t nb_samples)
{
_nb_samples = nb_samples;

if(_priv_data) {
_priv_data->nb_samples = nb_samples;
}
}

cmn::AudioChannel &GetChannels()
Expand Down Expand Up @@ -250,6 +254,9 @@ class MediaFrame
info.AppendFormat("Type(%s) ", cmn::GetMediaTypeString(GetMediaType()).CStr());
info.AppendFormat("PTS(%" PRId64 ") ", GetPts());
info.AppendFormat("Duration(%" PRId64 ") ", GetDuration());
if(_priv_data != nullptr) {
info.AppendFormat("NbSamples(%d) ", GetNbSamples());
}

return info;
}
Expand Down
2 changes: 1 addition & 1 deletion src/projects/transcoder/transcoder_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ std::shared_ptr<TranscodeDecoder> TranscodeDecoder::Create(
decoder->SetDecoderId(decoder_id);
decoder->SetCompleteHandler(complete_handler);

logti("The decoder has been created successfully. track(#%d) codec(%s), module(%s:%d)",
logti("The decoder has been created. track(#%d) codec(%s), module(%s:%d)",
track->GetId(),
cmn::GetCodecIdToString(track->GetCodecId()).CStr(),
cmn::GetStringFromCodecModuleId(track->GetCodecModuleId()).CStr(),
Expand Down
4 changes: 2 additions & 2 deletions src/projects/transcoder/transcoder_encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ std::shared_ptr<TranscodeEncoder> TranscodeEncoder::Create(
encoder->SetEncoderId(encoder_id);
encoder->SetCompleteHandler(complete_handler);

logti("The encoder has been created successfully. track(#%d), codec(%s), module(%s:%d)",
logti("The encoder has been created. track(#%d), codec(%s), module(%s:%d)",
track->GetId(),
cmn::GetCodecIdToString(track->GetCodecId()).CStr(),
cmn::GetStringFromCodecModuleId(track->GetCodecModuleId()).CStr(),
Expand Down Expand Up @@ -493,7 +493,7 @@ void TranscodeEncoder::CodecThread()

if(GetRefTrack()->GetMediaType() == cmn::MediaType::Audio)
{
// TODO : If the pts value are under zero, the dash packetizer does not work.
// If the pts value are under zero, the dash packetizer does not work.
if (media_packet->GetPts() < 0)
{
continue;
Expand Down

0 comments on commit ad1739a

Please sign in to comment.