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

Side by Side Diff: media/base/filter_host_impl.h

Issue 149215: Big media::Pipeline cleanup. (Closed)
Patch Set: Test Created 11 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
« no previous file with comments | « media/base/filter_host.h ('k') | media/base/filter_host_impl.cc » ('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) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2008-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 // Implementation of FilterHost. 5 // Implementation of FilterHost.
6 6
7 #ifndef MEDIA_BASE_FILTER_HOST_IMPL_H_ 7 #ifndef MEDIA_BASE_FILTER_HOST_IMPL_H_
8 #define MEDIA_BASE_FILTER_HOST_IMPL_H_ 8 #define MEDIA_BASE_FILTER_HOST_IMPL_H_
9 9
10 #include "base/task.h" 10 #include "base/task.h"
11 #include "media/base/filter_host.h" 11 #include "media/base/filter_host.h"
12 #include "media/base/pipeline_impl.h" 12 #include "media/base/pipeline_impl.h"
13 13
14 namespace media { 14 namespace media {
15 15
16 class FilterHostImpl : public FilterHost { 16 class FilterHostImpl : public FilterHost {
17 public: 17 public:
18 // FilterHost interface. 18 // FilterHost interface.
19 virtual const PipelineStatus* GetPipelineStatus() const;
20 virtual void SetTimeUpdateCallback(Callback1<base::TimeDelta>::Type* cb);
21 virtual void ScheduleTimeUpdateCallback(base::TimeDelta time);
22 virtual void InitializationComplete(); 19 virtual void InitializationComplete();
23 virtual void Error(PipelineError error); 20 virtual void Error(PipelineError error);
21 virtual base::TimeDelta GetTime() const;
24 virtual void SetTime(base::TimeDelta time); 22 virtual void SetTime(base::TimeDelta time);
25 virtual void SetDuration(base::TimeDelta duration); 23 virtual void SetDuration(base::TimeDelta duration);
26 virtual void SetBufferedTime(base::TimeDelta buffered_time); 24 virtual void SetBufferedTime(base::TimeDelta buffered_time);
27 virtual void SetTotalBytes(int64 total_bytes); 25 virtual void SetTotalBytes(int64 total_bytes);
28 virtual void SetBufferedBytes(int64 buffered_bytes); 26 virtual void SetBufferedBytes(int64 buffered_bytes);
29 virtual void SetVideoSize(size_t width, size_t height); 27 virtual void SetVideoSize(size_t width, size_t height);
30 28
31 // These methods are public, but are intended for use by the 29 // These methods are public, but are intended for use by the
32 // PipelineThread class only. 30 // PipelineThread class only.
33 31
34 // Creates a FilterHostImpl object and populates the filter_type_ member 32 // Creates a FilterHostImpl object and populates the |filter_type_| member
35 // by calling the Filter class's static filter_type() method. This ensures 33 // by calling the Filter class's static filter_type() method. This ensures
36 // that the GetFilter method can safely cast the filter interface from the 34 // that the GetFilter method can safely cast the filter interface from the
37 // MediaFilter base class interface to the specific Filter interface. 35 // MediaFilter base class interface to the specific Filter interface.
38 template <class Filter> 36 template <class Filter>
39 FilterHostImpl(PipelineThread* pipeline_thread, Filter* filter) 37 FilterHostImpl(PipelineThread* pipeline_thread, Filter* filter)
40 : pipeline_thread_(pipeline_thread), 38 : pipeline_thread_(pipeline_thread),
41 filter_type_(Filter::filter_type()), 39 filter_type_(Filter::filter_type()),
42 filter_(filter), 40 filter_(filter),
43 scheduled_time_update_task_(NULL),
44 stopped_(false) { 41 stopped_(false) {
45 } 42 }
46 ~FilterHostImpl() {} 43 ~FilterHostImpl() {}
47 44
48 // If this FilterHost contains a filter of the specifed Filter class, then 45 // If this FilterHost contains a filter of the specified Filter class, then
49 // this method returns a pointer to the interface, otherwise it returns NULL 46 // this method returns a pointer to the interface, otherwise it returns NULL
50 // in |*filter_out|. 47 // in |*filter_out|.
51 template <class Filter> 48 template <class Filter>
52 void GetFilter(scoped_refptr<Filter>* filter_out) const { 49 void GetFilter(scoped_refptr<Filter>* filter_out) const {
53 *filter_out = (Filter::filter_type() == filter_type_) ? 50 *filter_out = (Filter::filter_type() == filter_type_) ?
54 reinterpret_cast<Filter*>(media_filter()) : NULL; 51 reinterpret_cast<Filter*>(media_filter()) : NULL;
55 } 52 }
56 53
57 // Call the filter if it has registered a time update callback if the filter
58 // has registered one though the FilterHost::SetTimeUpdateCallback method.
59 void RunTimeUpdateCallback(base::TimeDelta time);
60
61 // Stops the filter. 54 // Stops the filter.
62 void Stop(); 55 void Stop();
63 56
64 // Used by the PipelineThread to call Seek and SetRate methods on filters. 57 // Used by the PipelineThread to call Seek and SetRate methods on filters.
65 MediaFilter* media_filter() const { return filter_; } 58 MediaFilter* media_filter() const { return filter_; }
66 59
67 private: 60 private:
68 // This task class is used to schedule a time update callback for the filter.
69 // Because a filter may call the ScheduleTimeUpdateCallback method from any
70 // thread, and becuase we only want to honor the last call to that method,
71 // we always have only one current task.
72 // We are required to keep a pointer to the host and a boolean that tells
73 // us if the task was canceled because the cancelation could happen on one
74 // thread, just as the pipeline thread is calling the Run method on this task.
75 // So, we can't just NULL out the host_ to cancel this because it could
76 // fault. Once we have called the host, it needs to enter it's critical
77 // section and make sure that the task that has Run is, in fact, the last one
78 // that was scheduled.
79 // In the case where the filter host is Stopping (or being destroyed), it will
80 // be guaranteed to happen on the pipeline thread, thus making the setting
81 // of the |canceled_| bool thread safe since the task would only execute on
82 // the pipeline thread. This means that it could be possible for a task to
83 // hold a pointer to a |host_| that has been deleted, but it will never access
84 // that pointer because the task was canceled.
85 class TimeUpdateTask : public CancelableTask {
86 public:
87 explicit TimeUpdateTask(FilterHostImpl* host)
88 : host_(host),
89 canceled_(false) {}
90
91 virtual void Run() {
92 if (!canceled_) {
93 host_->RunScheduledTimeUpdateCallback(this);
94 }
95 }
96
97 virtual void Cancel() {
98 canceled_ = true;
99 }
100
101 private:
102 FilterHostImpl* const host_;
103 bool canceled_;
104
105 DISALLOW_COPY_AND_ASSIGN(TimeUpdateTask);
106 };
107
108 // Method used by the TimeUpdateTask to call back to the filter.
109 void RunScheduledTimeUpdateCallback(TimeUpdateTask* caller);
110
111 // Useful method for getting the pipeline. 61 // Useful method for getting the pipeline.
112 PipelineImpl* pipeline() const { return pipeline_thread_->pipeline(); } 62 PipelineImpl* pipeline() const { return pipeline_thread_->pipeline(); }
113 63
114 // PipelineThread that owns this FilterHostImpl. 64 // PipelineThread that owns this FilterHostImpl.
115 PipelineThread* const pipeline_thread_; 65 PipelineThread* const pipeline_thread_;
116 66
117 // The FilterType of the filter this host contains. 67 // The FilterType of the filter this host contains.
118 FilterType const filter_type_; 68 FilterType const filter_type_;
119 69
120 // A pointer to the filter's MediaFilter base interface. 70 // A pointer to the filter's MediaFilter base interface.
121 scoped_refptr<MediaFilter> filter_; 71 scoped_refptr<MediaFilter> filter_;
122 72
123 // An optional callback that will be called when the time is updated.
124 scoped_ptr<Callback1<base::TimeDelta>::Type> time_update_callback_;
125
126 // Critical section used for scheduled time update callbacks. 73 // Critical section used for scheduled time update callbacks.
127 Lock time_update_lock_; 74 Lock time_update_lock_;
128 75
129 // Pointer to the current time update callback task.
130 TimeUpdateTask* scheduled_time_update_task_;
131
132 // Used to avoid calling Filter's Stop() method multiple times. 76 // Used to avoid calling Filter's Stop() method multiple times.
133 bool stopped_; 77 bool stopped_;
134 78
135 DISALLOW_COPY_AND_ASSIGN(FilterHostImpl); 79 DISALLOW_COPY_AND_ASSIGN(FilterHostImpl);
136 }; 80 };
137 81
138 } // namespace media 82 } // namespace media
139 83
140 #endif // MEDIA_BASE_FILTER_HOST_IMPL_H_ 84 #endif // MEDIA_BASE_FILTER_HOST_IMPL_H_
OLDNEW
« no previous file with comments | « media/base/filter_host.h ('k') | media/base/filter_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698