Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(348)

Unified Diff: media/filters/ffmpeg_demuxer.cc

Issue 113598: Use av_rescale_q() for converting FFmpeg timestamps to base::TimeDelta. (Closed)
Patch Set: Tweaksd Created 11 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/filters/ffmpeg_demuxer.h ('k') | third_party/ffmpeg/avutil-50.def » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/filters/ffmpeg_demuxer.cc
diff --git a/media/filters/ffmpeg_demuxer.cc b/media/filters/ffmpeg_demuxer.cc
index 077314e6c64179aabfa1777f97174206249c767f..ab3974b81a34ddde381de3aa5a006b95de486c76 100644
--- a/media/filters/ffmpeg_demuxer.cc
+++ b/media/filters/ffmpeg_demuxer.cc
@@ -51,7 +51,7 @@ class AVPacketBuffer : public Buffer {
FFmpegDemuxerStream::FFmpegDemuxerStream(FFmpegDemuxer* demuxer,
AVStream* stream)
: demuxer_(demuxer),
- av_stream_(stream),
+ stream_(stream),
discontinuous_(false) {
DCHECK(demuxer_);
@@ -70,12 +70,8 @@ FFmpegDemuxerStream::FFmpegDemuxerStream(FFmpegDemuxer* demuxer,
break;
}
- // Calculate the time base and duration in microseconds.
- int64 time_base_us = static_cast<int64>(av_q2d(stream->time_base) *
- base::Time::kMicrosecondsPerSecond);
- int64 duration_us = static_cast<int64>(time_base_us * stream->duration);
- time_base_ = base::TimeDelta::FromMicroseconds(time_base_us);
- duration_ = base::TimeDelta::FromMicroseconds(duration_us);
+ // Calculate the duration.
+ duration_ = ConvertTimestamp(stream->duration);
}
FFmpegDemuxerStream::~FFmpegDemuxerStream() {
@@ -106,8 +102,8 @@ bool FFmpegDemuxerStream::HasPendingReads() {
}
base::TimeDelta FFmpegDemuxerStream::EnqueuePacket(AVPacket* packet) {
- base::TimeDelta timestamp = time_base_ * packet->pts;
- base::TimeDelta duration = time_base_ * packet->duration;
+ base::TimeDelta timestamp = ConvertTimestamp(packet->pts);
+ base::TimeDelta duration = ConvertTimestamp(packet->duration);
Buffer* buffer = new AVPacketBuffer(packet, timestamp, duration);
DCHECK(buffer);
{
@@ -166,6 +162,12 @@ bool FFmpegDemuxerStream::FulfillPendingReads() {
return pending_reads;
}
+base::TimeDelta FFmpegDemuxerStream::ConvertTimestamp(int64 timestamp) {
+ AVRational time_base = { 1, base::Time::kMicrosecondsPerSecond };
+ int64 microseconds = av_rescale_q(timestamp, stream_->time_base, time_base);
+ return base::TimeDelta::FromMicroseconds(microseconds);
+}
+
//
// FFmpegDemuxer
« no previous file with comments | « media/filters/ffmpeg_demuxer.h ('k') | third_party/ffmpeg/avutil-50.def » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698