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

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

Issue 7461016: Replace VideoDecoder::media_format() with significantly simpler width()/height() methods. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src
Patch Set: Created 9 years, 5 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // VideoRendererBase creates its own thread for the sole purpose of timing frame 5 // VideoRendererBase creates its own thread for the sole purpose of timing frame
6 // presentation. It handles reading from the decoder and stores the results in 6 // presentation. It handles reading from the decoder and stores the results in
7 // a queue of decoded frames, calling OnFrameAvailable() on subclasses to notify 7 // a queue of decoded frames, calling OnFrameAvailable() on subclasses to notify
8 // when a frame is ready to display. 8 // when a frame is ready to display.
9 // 9 //
10 // The media filter methods Initialize(), Stop(), SetPlaybackRate() and Seek() 10 // The media filter methods Initialize(), Stop(), SetPlaybackRate() and Seek()
(...skipping 18 matching lines...) Expand all
29 29
30 // TODO(scherkus): to avoid subclasses, consider using a peer/delegate interface 30 // TODO(scherkus): to avoid subclasses, consider using a peer/delegate interface
31 // and pass in a reference to the constructor. 31 // and pass in a reference to the constructor.
32 class VideoRendererBase 32 class VideoRendererBase
33 : public VideoRenderer, 33 : public VideoRenderer,
34 public base::PlatformThread::Delegate { 34 public base::PlatformThread::Delegate {
35 public: 35 public:
36 VideoRendererBase(); 36 VideoRendererBase();
37 virtual ~VideoRendererBase(); 37 virtual ~VideoRendererBase();
38 38
39 // Helper method to parse out video-related information from a MediaFormat.
40 // Returns true all the required parameters are existent in |media_format|.
41 // |surface_format_out|, |width_out|, |height_out| can be NULL where the
42 // result is not needed.
43 static bool ParseMediaFormat(
44 const MediaFormat& media_format,
45 VideoFrame::Format* surface_format_out,
46 int* width_out, int* height_out);
47
48 // Filter implementation. 39 // Filter implementation.
49 virtual void Play(FilterCallback* callback); 40 virtual void Play(FilterCallback* callback);
50 virtual void Pause(FilterCallback* callback); 41 virtual void Pause(FilterCallback* callback);
51 virtual void Flush(FilterCallback* callback); 42 virtual void Flush(FilterCallback* callback);
52 virtual void Stop(FilterCallback* callback); 43 virtual void Stop(FilterCallback* callback);
53 virtual void SetPlaybackRate(float playback_rate); 44 virtual void SetPlaybackRate(float playback_rate);
54 virtual void Seek(base::TimeDelta time, const FilterStatusCB& cb); 45 virtual void Seek(base::TimeDelta time, const FilterStatusCB& cb);
55 46
56 // VideoRenderer implementation. 47 // VideoRenderer implementation.
57 virtual void Initialize(VideoDecoder* decoder, 48 virtual void Initialize(VideoDecoder* decoder,
(...skipping 11 matching lines...) Expand all
69 // is NULL. This could happen when before pipeline is pre-rolled or during 60 // is NULL. This could happen when before pipeline is pre-rolled or during
70 // pause/flush/seek. 61 // pause/flush/seek.
71 void GetCurrentFrame(scoped_refptr<VideoFrame>* frame_out); 62 void GetCurrentFrame(scoped_refptr<VideoFrame>* frame_out);
72 void PutCurrentFrame(scoped_refptr<VideoFrame> frame); 63 void PutCurrentFrame(scoped_refptr<VideoFrame> frame);
73 64
74 protected: 65 protected:
75 // Subclass interface. Called before any other initialization in the base 66 // Subclass interface. Called before any other initialization in the base
76 // class takes place. 67 // class takes place.
77 // 68 //
78 // Implementors typically use the media format of |decoder| to create their 69 // Implementors typically use the media format of |decoder| to create their
79 // output surfaces. Implementors should NOT call InitializationComplete(). 70 // output surfaces.
80 virtual bool OnInitialize(VideoDecoder* decoder) = 0; 71 virtual bool OnInitialize(VideoDecoder* decoder) = 0;
81 72
82 // Subclass interface. Called after all other stopping actions take place. 73 // Subclass interface. Called after all other stopping actions take place.
83 // 74 //
84 // Implementors should perform any necessary cleanup before calling the 75 // Implementors should perform any necessary cleanup before calling the
85 // callback. 76 // callback.
86 virtual void OnStop(FilterCallback* callback) = 0; 77 virtual void OnStop(FilterCallback* callback) = 0;
87 78
88 // Subclass interface. Called when a new frame is ready for display, which 79 // Subclass interface. Called when a new frame is ready for display, which
89 // can be accessed via GetCurrentFrame(). 80 // can be accessed via GetCurrentFrame().
90 // 81 //
91 // Implementors should avoid doing any sort of heavy work in this method and 82 // Implementors should avoid doing any sort of heavy work in this method and
92 // instead post a task to a common/worker thread to handle rendering. Slowing 83 // instead post a task to a common/worker thread to handle rendering. Slowing
93 // down the video thread may result in losing synchronization with audio. 84 // down the video thread may result in losing synchronization with audio.
94 // 85 //
95 // IMPORTANT: This method is called on the video renderer thread, which is 86 // IMPORTANT: This method is called on the video renderer thread, which is
96 // different from the thread OnInitialize(), OnStop(), and the rest of the 87 // different from the thread OnInitialize(), OnStop(), and the rest of the
97 // class executes on. 88 // class executes on.
98 virtual void OnFrameAvailable() = 0; 89 virtual void OnFrameAvailable() = 0;
99 90
100 virtual VideoDecoder* GetDecoder();
101
102 int width() { return width_; }
103 int height() { return height_; }
104 VideoFrame::Format surface_format() { return surface_format_; }
105
106 void ReadInput(scoped_refptr<VideoFrame> frame); 91 void ReadInput(scoped_refptr<VideoFrame> frame);
107 92
108 private: 93 private:
109 // Callback from video decoder to deliver decoded video frames and decrements 94 // Callback from video decoder to deliver decoded video frames and decrements
110 // |pending_reads_|. 95 // |pending_reads_|.
111 void ConsumeVideoFrame(scoped_refptr<VideoFrame> frame); 96 void ConsumeVideoFrame(scoped_refptr<VideoFrame> frame);
112 97
113 // Helper method that schedules an asynchronous read from the decoder and 98 // Helper method that schedules an asynchronous read from the decoder and
114 // increments |pending_reads_|. 99 // increments |pending_reads_|.
115 // 100 //
(...skipping 18 matching lines...) Expand all
134 void EnterErrorState_Locked(PipelineStatus status); 119 void EnterErrorState_Locked(PipelineStatus status);
135 120
136 // Helper function that flushes the buffers when a Stop() or error occurs. 121 // Helper function that flushes the buffers when a Stop() or error occurs.
137 void DoStopOrErrorFlush_Locked(); 122 void DoStopOrErrorFlush_Locked();
138 123
139 // Used for accessing data members. 124 // Used for accessing data members.
140 base::Lock lock_; 125 base::Lock lock_;
141 126
142 scoped_refptr<VideoDecoder> decoder_; 127 scoped_refptr<VideoDecoder> decoder_;
143 128
144 int width_;
145 int height_;
146 VideoFrame::Format surface_format_;
147
148 // Queue of incoming frames as well as the current frame since the last time 129 // Queue of incoming frames as well as the current frame since the last time
149 // OnFrameAvailable() was called. 130 // OnFrameAvailable() was called.
150 typedef std::deque< scoped_refptr<VideoFrame> > VideoFrameQueue; 131 typedef std::deque< scoped_refptr<VideoFrame> > VideoFrameQueue;
151 VideoFrameQueue frames_queue_ready_; 132 VideoFrameQueue frames_queue_ready_;
152 VideoFrameQueue frames_queue_done_; 133 VideoFrameQueue frames_queue_done_;
153 scoped_refptr<VideoFrame> current_frame_; 134 scoped_refptr<VideoFrame> current_frame_;
154 scoped_refptr<VideoFrame> last_available_frame_; 135 scoped_refptr<VideoFrame> last_available_frame_;
155 136
156 // Used to signal |thread_| as frames are added to |frames_|. Rule of thumb: 137 // Used to signal |thread_| as frames are added to |frames_|. Rule of thumb:
157 // always check |state_| to see if it was set to STOPPED after waking up! 138 // always check |state_| to see if it was set to STOPPED after waking up!
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 scoped_ptr<StatisticsCallback> statistics_callback_; 199 scoped_ptr<StatisticsCallback> statistics_callback_;
219 200
220 base::TimeDelta seek_timestamp_; 201 base::TimeDelta seek_timestamp_;
221 202
222 DISALLOW_COPY_AND_ASSIGN(VideoRendererBase); 203 DISALLOW_COPY_AND_ASSIGN(VideoRendererBase);
223 }; 204 };
224 205
225 } // namespace media 206 } // namespace media
226 207
227 #endif // MEDIA_FILTERS_VIDEO_RENDERER_BASE_H_ 208 #endif // MEDIA_FILTERS_VIDEO_RENDERER_BASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698