@@ -91,10 +91,6 @@ static AvPlayerStreamType CodecTypeToStreamType(AVMediaType codec_type) {
91
91
}
92
92
}
93
93
94
- static f32 AVRationalToF32 (const AVRational rational) {
95
- return f32 (rational.num ) / rational.den ;
96
- }
97
-
98
94
bool AvPlayerSource::GetStreamInfo (u32 stream_index, AvPlayerStreamInfo& info) {
99
95
info = {};
100
96
if (m_avformat_context == nullptr || stream_index >= m_avformat_context->nb_streams ) {
@@ -265,11 +261,11 @@ bool AvPlayerSource::Stop() {
265
261
m_demuxer_thread.Stop ();
266
262
267
263
if (m_current_audio_frame.has_value ()) {
268
- m_audio_buffers.Push (std::move (m_current_audio_frame. value () ));
264
+ m_audio_buffers.Push (std::move (m_current_audio_frame-> buffer ));
269
265
m_current_audio_frame.reset ();
270
266
}
271
267
if (m_current_video_frame.has_value ()) {
272
- m_video_buffers.Push (std::move (m_current_video_frame. value () ));
268
+ m_video_buffers.Push (std::move (m_current_video_frame-> buffer ));
273
269
m_current_video_frame.reset ();
274
270
}
275
271
@@ -281,12 +277,12 @@ bool AvPlayerSource::Stop() {
281
277
}
282
278
283
279
void AvPlayerSource::Pause () {
284
- m_last_paused_time = std::chrono::high_resolution_clock::now ();
280
+ m_pause_time = std::chrono::high_resolution_clock::now ();
285
281
m_is_paused = true ;
286
282
}
287
283
288
284
void AvPlayerSource::Resume () {
289
- m_stalled_time += std::chrono::high_resolution_clock::now () - m_last_paused_time ;
285
+ m_pause_duration += std::chrono::high_resolution_clock::now () - m_pause_time ;
290
286
m_is_paused = false ;
291
287
}
292
288
@@ -313,23 +309,22 @@ bool AvPlayerSource::GetVideoData(AvPlayerFrameInfoEx& video_info) {
313
309
return false ;
314
310
}
315
311
316
- const auto & last_frame = m_video_frames.Front ();
312
+ const auto & new_frame = m_video_frames.Front ();
317
313
if (m_state.GetSyncMode () == AvPlayerAvSyncMode::Default) {
318
- const auto current_time =
319
- m_audio_stream_index.has_value () ? m_last_audio_packet_time : CurrentTime ();
320
- if (0 < current_time && current_time < last_frame.info .timestamp ) {
314
+ const auto current_time = CurrentTime ();
315
+ if (0 < current_time && current_time < new_frame.info .timestamp ) {
321
316
return false ;
322
317
}
323
318
}
324
319
325
320
auto frame = m_video_frames.Pop ();
326
321
if (m_current_video_frame.has_value ()) {
327
322
// return the buffer to the queue
328
- m_video_buffers.Push (std::move (m_current_video_frame. value () ));
323
+ m_video_buffers.Push (std::move (m_current_video_frame-> buffer ));
329
324
m_video_buffers_cv.Notify ();
330
325
}
331
- m_current_video_frame = std::move (frame->buffer );
332
326
video_info = frame->info ;
327
+ m_current_video_frame = std::move (frame);
333
328
return true ;
334
329
}
335
330
@@ -345,18 +340,17 @@ bool AvPlayerSource::GetAudioData(AvPlayerFrameInfo& audio_info) {
345
340
auto frame = m_audio_frames.Pop ();
346
341
if (m_current_audio_frame.has_value ()) {
347
342
// return the buffer to the queue
348
- m_audio_buffers.Push (std::move (m_current_audio_frame. value () ));
343
+ m_audio_buffers.Push (std::move (m_current_audio_frame-> buffer ));
349
344
m_audio_buffers_cv.Notify ();
350
345
}
351
- m_current_audio_frame = std::move (frame->buffer );
352
- m_last_audio_packet_time = frame->info .timestamp ;
353
346
354
347
audio_info = {};
355
348
audio_info.timestamp = frame->info .timestamp ;
356
349
audio_info.p_data = reinterpret_cast <u8*>(frame->info .p_data );
357
350
audio_info.details .audio .sample_rate = frame->info .details .audio .sample_rate ;
358
351
audio_info.details .audio .size = frame->info .details .audio .size ;
359
352
audio_info.details .audio .channel_count = frame->info .details .audio .channel_count ;
353
+ m_current_audio_frame = std::move (frame);
360
354
return true ;
361
355
}
362
356
@@ -365,7 +359,8 @@ u64 AvPlayerSource::CurrentTime() {
365
359
return 0 ;
366
360
}
367
361
using namespace std ::chrono;
368
- return duration_cast<milliseconds>(high_resolution_clock::now () - m_start_time - m_stalled_time)
362
+ return duration_cast<milliseconds>(high_resolution_clock::now () - m_start_time -
363
+ m_pause_duration)
369
364
.count ();
370
365
}
371
366
@@ -568,7 +563,7 @@ Frame AvPlayerSource::PrepareVideoFrame(FrameBuffer buffer, const AVFrame& frame
568
563
{
569
564
.width = width,
570
565
.height = height,
571
- .aspect_ratio = AVRationalToF32 (frame.sample_aspect_ratio ),
566
+ .aspect_ratio = ( float ) av_q2d (frame.sample_aspect_ratio ),
572
567
.crop_left_offset = u32 (frame.crop_left ),
573
568
.crop_right_offset = u32 (frame.crop_right + (width - frame.width )),
574
569
.crop_top_offset = u32 (frame.crop_top ),
0 commit comments