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

Side by Side Diff: media/filters/audio_renderer_base.h

Issue 159476: Merge 21611 - Implemented proper pausethenseek behaviour for the media pipeli... (Closed) Base URL: svn://chrome-svn/chrome/branches/195/src/
Patch Set: Created 11 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « media/base/pipeline_impl_unittest.cc ('k') | media/filters/audio_renderer_base.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:mergeinfo
Merged /branches/chrome_webkit_merge_branch/media/filters/audio_renderer_base.h:r69-2775
Merged /trunk/src/media/filters/audio_renderer_base.h:r21611
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 // AudioRendererBase takes care of the tricky queuing work and provides simple 5 // AudioRendererBase takes care of the tricky queuing work and provides simple
6 // methods for subclasses to peek and poke at audio data. In addition to 6 // methods for subclasses to peek and poke at audio data. In addition to
7 // AudioRenderer interface methods this classes doesn't implement, subclasses 7 // AudioRenderer interface methods this classes doesn't implement, subclasses
8 // must also implement the following methods: 8 // must also implement the following methods:
9 // OnInitialized 9 // OnInitialized
10 // OnStop 10 // OnStop
(...skipping 12 matching lines...) Expand all
23 #include "base/lock.h" 23 #include "base/lock.h"
24 #include "media/base/buffers.h" 24 #include "media/base/buffers.h"
25 #include "media/base/factory.h" 25 #include "media/base/factory.h"
26 #include "media/base/filters.h" 26 #include "media/base/filters.h"
27 27
28 namespace media { 28 namespace media {
29 29
30 class AudioRendererBase : public AudioRenderer { 30 class AudioRendererBase : public AudioRenderer {
31 public: 31 public:
32 // MediaFilter implementation. 32 // MediaFilter implementation.
33 virtual void Play(FilterCallback* callback);
34 virtual void Pause(FilterCallback* callback);
33 virtual void Stop(); 35 virtual void Stop();
34 36
35 virtual void Seek(base::TimeDelta time, FilterCallback* callback); 37 virtual void Seek(base::TimeDelta time, FilterCallback* callback);
36 38
37 // AudioRenderer implementation. 39 // AudioRenderer implementation.
38 virtual void Initialize(AudioDecoder* decoder, FilterCallback* callback); 40 virtual void Initialize(AudioDecoder* decoder, FilterCallback* callback);
39 41
40 protected: 42 protected:
41 // The default maximum size of the queue. 43 // The default maximum size of the queue.
42 static const size_t kDefaultMaxQueueSize; 44 static const size_t kDefaultMaxQueueSize;
43 45
44 // Only allow a factory to create this class. 46 // Only allow a factory to create this class.
45 explicit AudioRendererBase(size_t max_queue_size); 47 explicit AudioRendererBase(size_t max_queue_size);
46 virtual ~AudioRendererBase(); 48 virtual ~AudioRendererBase();
47 49
48 // Called by Initialize(). |media_format| is the format of the AudioDecoder. 50 // Called by Initialize(). |media_format| is the format of the AudioDecoder.
49 // Subclasses should return true if they were able to initialize, false 51 // Subclasses should return true if they were able to initialize, false
50 // otherwise. 52 // otherwise.
51 virtual bool OnInitialize(const MediaFormat& media_format) = 0; 53 virtual bool OnInitialize(const MediaFormat& media_format) = 0;
52 54
53 // Called by Stop(). Subclasses should perform any necessary cleanup during 55 // Called by Stop(). Subclasses should perform any necessary cleanup during
54 // this time, such as stopping any running threads. 56 // this time, such as stopping any running threads.
55 virtual void OnStop() = 0; 57 virtual void OnStop() = 0;
56 58
57 // Called when a AudioDecoder::Read() completes. 59 // Called when a AudioDecoder::Read() completes and decrements
60 // |pending_reads_|.
58 virtual void OnReadComplete(Buffer* buffer_in); 61 virtual void OnReadComplete(Buffer* buffer_in);
59 62
60 // Fills the given buffer with audio data by dequeuing buffers and copying the 63 // Fills the given buffer with audio data by dequeuing buffers and copying the
61 // data into the |dest|. FillBuffer() also takes care of updating the clock. 64 // data into the |dest|. FillBuffer() also takes care of updating the clock.
62 // Returns the number of bytes copied into |dest|, which may be less than 65 // Returns the number of bytes copied into |dest|, which may be less than
63 // equal to |len|. 66 // equal to |len|.
64 // 67 //
65 // If this method is returns less bytes than |len| (including zero), it could 68 // If this method is returns less bytes than |len| (including zero), it could
66 // be a sign that the pipeline is stalled or unable to stream the data fast 69 // be a sign that the pipeline is stalled or unable to stream the data fast
67 // enough. In such scenarios, the callee should zero out unused portions 70 // enough. In such scenarios, the callee should zero out unused portions
(...skipping 12 matching lines...) Expand all
80 float rate, 83 float rate,
81 const base::TimeDelta& playback_delay); 84 const base::TimeDelta& playback_delay);
82 85
83 // Helper to parse a media format and return whether we were successful 86 // Helper to parse a media format and return whether we were successful
84 // retrieving all the information we care about. 87 // retrieving all the information we care about.
85 static bool ParseMediaFormat(const MediaFormat& media_format, 88 static bool ParseMediaFormat(const MediaFormat& media_format,
86 int* channels_out, int* sample_rate_out, 89 int* channels_out, int* sample_rate_out,
87 int* sample_bits_out); 90 int* sample_bits_out);
88 91
89 private: 92 private:
90 // Helper method that schedules an asynchronous read from the decoder. 93 // Helper method that schedules an asynchronous read from the decoder and
94 // increments |pending_reads_|.
91 // 95 //
92 // Safe to call from any thread. 96 // Safe to call from any thread.
93 void ScheduleRead(); 97 void ScheduleRead_Locked();
94 98
95 // Audio decoder. 99 // Audio decoder.
96 scoped_refptr<AudioDecoder> decoder_; 100 scoped_refptr<AudioDecoder> decoder_;
97 101
98 // Maximum queue size, configuration parameter passed in during construction. 102 // Maximum queue size, configuration parameter passed in during construction.
99 size_t max_queue_size_; 103 size_t max_queue_size_;
100 104
101 // Queued audio data. 105 // Queued audio data.
102 typedef std::deque< scoped_refptr<Buffer> > BufferQueue; 106 typedef std::deque< scoped_refptr<Buffer> > BufferQueue;
103 BufferQueue queue_; 107 BufferQueue queue_;
104 Lock lock_; 108 Lock lock_;
105 109
106 // Remembers the amount of remaining audio data for the front buffer. 110 // Remembers the amount of remaining audio data for the front buffer.
107 size_t data_offset_; 111 size_t data_offset_;
108 112
109 // Whether or not we're initialized. 113 // Simple state tracking variable.
110 bool initialized_; 114 enum State {
115 kUninitialized,
116 kPaused,
117 kSeeking,
118 kPlaying,
119 kStopped,
120 kError,
121 };
122 State state_;
111 123
112 // Whether or not we've stopped. 124 // Keeps track of our pending reads. We *must* have no pending reads before
113 bool stopped_; 125 // executing the pause callback, otherwise we breach the contract that all
126 // filters are idling.
127 //
128 // We use size_t since we compare against std::deque::size().
129 size_t pending_reads_;
114 130
115 // Audio time at end of last call to FillBuffer(). 131 // Audio time at end of last call to FillBuffer().
116 // TODO(ralphl): Update this value after seeking. 132 // TODO(ralphl): Update this value after seeking.
117 base::TimeDelta last_fill_buffer_time_; 133 base::TimeDelta last_fill_buffer_time_;
118 134
119 // Filter callbacks. 135 // Filter callbacks.
120 scoped_ptr<FilterCallback> initialize_callback_; 136 scoped_ptr<FilterCallback> pause_callback_;
137 scoped_ptr<FilterCallback> seek_callback_;
121 138
122 DISALLOW_COPY_AND_ASSIGN(AudioRendererBase); 139 DISALLOW_COPY_AND_ASSIGN(AudioRendererBase);
123 }; 140 };
124 141
125 } // namespace media 142 } // namespace media
126 143
127 #endif // MEDIA_FILTERS_AUDIO_RENDERER_BASE_H_ 144 #endif // MEDIA_FILTERS_AUDIO_RENDERER_BASE_H_
OLDNEW
« no previous file with comments | « media/base/pipeline_impl_unittest.cc ('k') | media/filters/audio_renderer_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698