OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/callback.h" | 6 #include "base/callback.h" |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 // | 28 // |
29 class AVPacketBuffer : public Buffer { | 29 class AVPacketBuffer : public Buffer { |
30 public: | 30 public: |
31 AVPacketBuffer(scoped_ptr_malloc<AVPacket, ScopedPtrAVFreePacket> packet, | 31 AVPacketBuffer(scoped_ptr_malloc<AVPacket, ScopedPtrAVFreePacket> packet, |
32 const base::TimeDelta& timestamp, | 32 const base::TimeDelta& timestamp, |
33 const base::TimeDelta& duration) | 33 const base::TimeDelta& duration) |
34 : Buffer(timestamp, duration), | 34 : Buffer(timestamp, duration), |
35 packet_(packet.Pass()) { | 35 packet_(packet.Pass()) { |
36 } | 36 } |
37 | 37 |
38 virtual ~AVPacketBuffer() {} | |
39 | |
40 // Buffer implementation. | 38 // Buffer implementation. |
41 virtual const uint8* GetData() const { | 39 virtual const uint8* GetData() const { |
42 return reinterpret_cast<const uint8*>(packet_->data); | 40 return reinterpret_cast<const uint8*>(packet_->data); |
43 } | 41 } |
44 | 42 |
45 virtual int GetDataSize() const { | 43 virtual int GetDataSize() const { |
46 return packet_->size; | 44 return packet_->size; |
47 } | 45 } |
48 | 46 |
| 47 protected: |
| 48 virtual ~AVPacketBuffer() {} |
| 49 |
49 private: | 50 private: |
50 scoped_ptr_malloc<AVPacket, ScopedPtrAVFreePacket> packet_; | 51 scoped_ptr_malloc<AVPacket, ScopedPtrAVFreePacket> packet_; |
51 | 52 |
52 DISALLOW_COPY_AND_ASSIGN(AVPacketBuffer); | 53 DISALLOW_COPY_AND_ASSIGN(AVPacketBuffer); |
53 }; | 54 }; |
54 | 55 |
55 | 56 |
56 // | 57 // |
57 // FFmpegDemuxerStream | 58 // FFmpegDemuxerStream |
58 // | 59 // |
(...skipping 18 matching lines...) Expand all Loading... |
77 break; | 78 break; |
78 default: | 79 default: |
79 NOTREACHED(); | 80 NOTREACHED(); |
80 break; | 81 break; |
81 } | 82 } |
82 | 83 |
83 // Calculate the duration. | 84 // Calculate the duration. |
84 duration_ = ConvertStreamTimestamp(stream->time_base, stream->duration); | 85 duration_ = ConvertStreamTimestamp(stream->time_base, stream->duration); |
85 } | 86 } |
86 | 87 |
87 FFmpegDemuxerStream::~FFmpegDemuxerStream() { | |
88 base::AutoLock auto_lock(lock_); | |
89 DCHECK(stopped_); | |
90 DCHECK(read_queue_.empty()); | |
91 DCHECK(buffer_queue_.empty()); | |
92 } | |
93 | |
94 bool FFmpegDemuxerStream::HasPendingReads() { | 88 bool FFmpegDemuxerStream::HasPendingReads() { |
95 DCHECK_EQ(MessageLoop::current(), demuxer_->message_loop()); | 89 DCHECK_EQ(MessageLoop::current(), demuxer_->message_loop()); |
96 base::AutoLock auto_lock(lock_); | 90 base::AutoLock auto_lock(lock_); |
97 DCHECK(!stopped_ || read_queue_.empty()) | 91 DCHECK(!stopped_ || read_queue_.empty()) |
98 << "Read queue should have been emptied if demuxing stream is stopped"; | 92 << "Read queue should have been emptied if demuxing stream is stopped"; |
99 return !read_queue_.empty(); | 93 return !read_queue_.empty(); |
100 } | 94 } |
101 | 95 |
102 void FFmpegDemuxerStream::EnqueuePacket( | 96 void FFmpegDemuxerStream::EnqueuePacket( |
103 scoped_ptr_malloc<AVPacket, ScopedPtrAVFreePacket> packet) { | 97 scoped_ptr_malloc<AVPacket, ScopedPtrAVFreePacket> packet) { |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 const AudioDecoderConfig& FFmpegDemuxerStream::audio_decoder_config() { | 251 const AudioDecoderConfig& FFmpegDemuxerStream::audio_decoder_config() { |
258 CHECK_EQ(type_, AUDIO); | 252 CHECK_EQ(type_, AUDIO); |
259 return audio_config_; | 253 return audio_config_; |
260 } | 254 } |
261 | 255 |
262 const VideoDecoderConfig& FFmpegDemuxerStream::video_decoder_config() { | 256 const VideoDecoderConfig& FFmpegDemuxerStream::video_decoder_config() { |
263 CHECK_EQ(type_, VIDEO); | 257 CHECK_EQ(type_, VIDEO); |
264 return video_config_; | 258 return video_config_; |
265 } | 259 } |
266 | 260 |
| 261 FFmpegDemuxerStream::~FFmpegDemuxerStream() { |
| 262 base::AutoLock auto_lock(lock_); |
| 263 DCHECK(stopped_); |
| 264 DCHECK(read_queue_.empty()); |
| 265 DCHECK(buffer_queue_.empty()); |
| 266 } |
| 267 |
267 // static | 268 // static |
268 base::TimeDelta FFmpegDemuxerStream::ConvertStreamTimestamp( | 269 base::TimeDelta FFmpegDemuxerStream::ConvertStreamTimestamp( |
269 const AVRational& time_base, int64 timestamp) { | 270 const AVRational& time_base, int64 timestamp) { |
270 if (timestamp == static_cast<int64>(AV_NOPTS_VALUE)) | 271 if (timestamp == static_cast<int64>(AV_NOPTS_VALUE)) |
271 return kNoTimestamp(); | 272 return kNoTimestamp(); |
272 | 273 |
273 return ConvertFromTimeBase(time_base, timestamp); | 274 return ConvertFromTimeBase(time_base, timestamp); |
274 } | 275 } |
275 | 276 |
276 // | 277 // |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 read_event_.Wait(); | 723 read_event_.Wait(); |
723 return last_read_bytes_; | 724 return last_read_bytes_; |
724 } | 725 } |
725 | 726 |
726 void FFmpegDemuxer::SignalReadCompleted(int size) { | 727 void FFmpegDemuxer::SignalReadCompleted(int size) { |
727 last_read_bytes_ = size; | 728 last_read_bytes_ = size; |
728 read_event_.Signal(); | 729 read_event_.Signal(); |
729 } | 730 } |
730 | 731 |
731 } // namespace media | 732 } // namespace media |
OLD | NEW |