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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/scoped_ptr.h" 5 #include "base/scoped_ptr.h"
6 #include "base/string_util.h" 6 #include "base/string_util.h"
7 #include "base/time.h" 7 #include "base/time.h"
8 #include "media/base/filter_host.h" 8 #include "media/base/filter_host.h"
9 #include "media/filters/ffmpeg_common.h" 9 #include "media/filters/ffmpeg_common.h"
10 #include "media/filters/ffmpeg_demuxer.h" 10 #include "media/filters/ffmpeg_demuxer.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 DISALLOW_COPY_AND_ASSIGN(AVPacketBuffer); 44 DISALLOW_COPY_AND_ASSIGN(AVPacketBuffer);
45 }; 45 };
46 46
47 47
48 // 48 //
49 // FFmpegDemuxerStream 49 // FFmpegDemuxerStream
50 // 50 //
51 FFmpegDemuxerStream::FFmpegDemuxerStream(FFmpegDemuxer* demuxer, 51 FFmpegDemuxerStream::FFmpegDemuxerStream(FFmpegDemuxer* demuxer,
52 AVStream* stream) 52 AVStream* stream)
53 : demuxer_(demuxer), 53 : demuxer_(demuxer),
54 av_stream_(stream), 54 stream_(stream),
55 discontinuous_(false) { 55 discontinuous_(false) {
56 DCHECK(demuxer_); 56 DCHECK(demuxer_);
57 57
58 // Determine our media format. 58 // Determine our media format.
59 switch (stream->codec->codec_type) { 59 switch (stream->codec->codec_type) {
60 case CODEC_TYPE_AUDIO: 60 case CODEC_TYPE_AUDIO:
61 media_format_.SetAsString(MediaFormat::kMimeType, 61 media_format_.SetAsString(MediaFormat::kMimeType,
62 mime_type::kFFmpegAudio); 62 mime_type::kFFmpegAudio);
63 break; 63 break;
64 case CODEC_TYPE_VIDEO: 64 case CODEC_TYPE_VIDEO:
65 media_format_.SetAsString(MediaFormat::kMimeType, 65 media_format_.SetAsString(MediaFormat::kMimeType,
66 mime_type::kFFmpegVideo); 66 mime_type::kFFmpegVideo);
67 break; 67 break;
68 default: 68 default:
69 NOTREACHED(); 69 NOTREACHED();
70 break; 70 break;
71 } 71 }
72 72
73 // Calculate the time base and duration in microseconds. 73 // Calculate the duration.
74 int64 time_base_us = static_cast<int64>(av_q2d(stream->time_base) * 74 duration_ = ConvertTimestamp(stream->duration);
75 base::Time::kMicrosecondsPerSecond);
76 int64 duration_us = static_cast<int64>(time_base_us * stream->duration);
77 time_base_ = base::TimeDelta::FromMicroseconds(time_base_us);
78 duration_ = base::TimeDelta::FromMicroseconds(duration_us);
79 } 75 }
80 76
81 FFmpegDemuxerStream::~FFmpegDemuxerStream() { 77 FFmpegDemuxerStream::~FFmpegDemuxerStream() {
82 // Since |buffer_queue_| uses scoped_refptr everything will get released. 78 // Since |buffer_queue_| uses scoped_refptr everything will get released.
83 while (!read_queue_.empty()) { 79 while (!read_queue_.empty()) {
84 delete read_queue_.front(); 80 delete read_queue_.front();
85 read_queue_.pop_front(); 81 read_queue_.pop_front();
86 } 82 }
87 } 83 }
88 84
(...skipping 10 matching lines...) Expand all
99 } 95 }
100 return interface_ptr; 96 return interface_ptr;
101 } 97 }
102 98
103 bool FFmpegDemuxerStream::HasPendingReads() { 99 bool FFmpegDemuxerStream::HasPendingReads() {
104 AutoLock auto_lock(lock_); 100 AutoLock auto_lock(lock_);
105 return !read_queue_.empty(); 101 return !read_queue_.empty();
106 } 102 }
107 103
108 base::TimeDelta FFmpegDemuxerStream::EnqueuePacket(AVPacket* packet) { 104 base::TimeDelta FFmpegDemuxerStream::EnqueuePacket(AVPacket* packet) {
109 base::TimeDelta timestamp = time_base_ * packet->pts; 105 base::TimeDelta timestamp = ConvertTimestamp(packet->pts);
110 base::TimeDelta duration = time_base_ * packet->duration; 106 base::TimeDelta duration = ConvertTimestamp(packet->duration);
111 Buffer* buffer = new AVPacketBuffer(packet, timestamp, duration); 107 Buffer* buffer = new AVPacketBuffer(packet, timestamp, duration);
112 DCHECK(buffer); 108 DCHECK(buffer);
113 { 109 {
114 AutoLock auto_lock(lock_); 110 AutoLock auto_lock(lock_);
115 buffer_queue_.push_back(buffer); 111 buffer_queue_.push_back(buffer);
116 } 112 }
117 FulfillPendingReads(); 113 FulfillPendingReads();
118 return timestamp; 114 return timestamp;
119 } 115 }
120 116
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 if (discontinuous_) { 155 if (discontinuous_) {
160 buffer->SetDiscontinuous(true); 156 buffer->SetDiscontinuous(true);
161 discontinuous_ = false; 157 discontinuous_ = false;
162 } 158 }
163 } 159 }
164 read_callback->Run(buffer); 160 read_callback->Run(buffer);
165 } 161 }
166 return pending_reads; 162 return pending_reads;
167 } 163 }
168 164
165 base::TimeDelta FFmpegDemuxerStream::ConvertTimestamp(int64 timestamp) {
166 AVRational time_base = { 1, base::Time::kMicrosecondsPerSecond };
167 int64 microseconds = av_rescale_q(timestamp, stream_->time_base, time_base);
168 return base::TimeDelta::FromMicroseconds(microseconds);
169 }
170
169 171
170 // 172 //
171 // FFmpegDemuxer 173 // FFmpegDemuxer
172 // 174 //
173 FFmpegDemuxer::FFmpegDemuxer() 175 FFmpegDemuxer::FFmpegDemuxer()
174 : thread_("DemuxerThread") { 176 : thread_("DemuxerThread") {
175 } 177 }
176 178
177 FFmpegDemuxer::~FFmpegDemuxer() { 179 FFmpegDemuxer::~FFmpegDemuxer() {
178 Stop(); 180 Stop();
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 StreamVector::iterator iter; 344 StreamVector::iterator iter;
343 for (iter = streams_.begin(); iter != streams_.end(); ++iter) { 345 for (iter = streams_.begin(); iter != streams_.end(); ++iter) {
344 if ((*iter)->HasPendingReads()) { 346 if ((*iter)->HasPendingReads()) {
345 return true; 347 return true;
346 } 348 }
347 } 349 }
348 return false; 350 return false;
349 } 351 }
350 352
351 } // namespace media 353 } // namespace media
OLDNEW
« 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