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

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

Issue 42029: Checking in media::FFmpegGlue, media::FFmpegDemuxer and tests. (Closed)
Patch Set: Created 11 years, 9 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/DEPS ('k') | media/base/pipeline.h » ('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. Use of this 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in the 2 // source code is governed by a BSD-style license that can be found in the
3 // LICENSE file. 3 // LICENSE file.
4 4
5 #ifndef MEDIA_BASE_MOCK_MEDIA_FILTERS_H_ 5 #ifndef MEDIA_BASE_MOCK_MEDIA_FILTERS_H_
6 #define MEDIA_BASE_MOCK_MEDIA_FILTERS_H_ 6 #define MEDIA_BASE_MOCK_MEDIA_FILTERS_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/waitable_event.h" 10 #include "base/waitable_event.h"
(...skipping 19 matching lines...) Expand all
30 }; 30 };
31 31
32 32
33 // This class is used by all of the mock filters to change the configuration 33 // This class is used by all of the mock filters to change the configuration
34 // of the desired pipeline. The test using this must ensure that the lifetime 34 // of the desired pipeline. The test using this must ensure that the lifetime
35 // of the object is at least as long as the lifetime of the filters, as this 35 // of the object is at least as long as the lifetime of the filters, as this
36 // is typically allocated on the stack. 36 // is typically allocated on the stack.
37 struct MockFilterConfig { 37 struct MockFilterConfig {
38 MockFilterConfig() 38 MockFilterConfig()
39 : data_source_behavior(MOCK_DATA_SOURCE_NORMAL_INIT), 39 : data_source_behavior(MOCK_DATA_SOURCE_NORMAL_INIT),
40 data_source_value('!'),
40 has_video(true), 41 has_video(true),
41 video_width(1280u), 42 video_width(1280u),
42 video_height(720u), 43 video_height(720u),
43 video_surface_format(VideoSurface::YV12), 44 video_surface_format(VideoSurface::YV12),
44 has_audio(true), 45 has_audio(true),
45 compressed_audio_mime_type(mime_type::kAACAudio), 46 compressed_audio_mime_type(mime_type::kAACAudio),
46 uncompressed_audio_mime_type(mime_type::kUncompressedAudio), 47 uncompressed_audio_mime_type(mime_type::kUncompressedAudio),
47 compressed_video_mime_type(mime_type::kH264AnnexB), 48 compressed_video_mime_type(mime_type::kH264AnnexB),
48 uncompressed_video_mime_type(mime_type::kUncompressedVideo), 49 uncompressed_video_mime_type(mime_type::kUncompressedVideo),
49 frame_duration(base::TimeDelta::FromMicroseconds(33333)), 50 frame_duration(base::TimeDelta::FromMicroseconds(33333)),
50 media_duration(base::TimeDelta::FromSeconds(5)), 51 media_duration(base::TimeDelta::FromSeconds(5)),
51 media_total_bytes(media_duration.InMilliseconds() * 250) { 52 media_total_bytes(media_duration.InMilliseconds() * 250) {
52 } 53 }
53 54
54 MockDataSourceBehavior data_source_behavior; 55 MockDataSourceBehavior data_source_behavior;
56 char data_source_value;
55 bool has_video; 57 bool has_video;
56 size_t video_width; 58 size_t video_width;
57 size_t video_height; 59 size_t video_height;
58 VideoSurface::Format video_surface_format; 60 VideoSurface::Format video_surface_format;
59 bool has_audio; 61 bool has_audio;
60 std::string compressed_audio_mime_type; 62 std::string compressed_audio_mime_type;
61 std::string uncompressed_audio_mime_type; 63 std::string uncompressed_audio_mime_type;
62 std::string compressed_video_mime_type; 64 std::string compressed_video_mime_type;
63 std::string uncompressed_video_mime_type; 65 std::string uncompressed_video_mime_type;
64 base::TimeDelta frame_duration; 66 base::TimeDelta frame_duration;
65 base::TimeDelta media_duration; 67 base::TimeDelta media_duration;
66 int64 media_total_bytes; 68 int64 media_total_bytes;
67 }; 69 };
68 70
69 71
70 class MockDataSource : public DataSource { 72 class MockDataSource : public DataSource {
71 public: 73 public:
72 static FilterFactory* CreateFactory(const MockFilterConfig* config) { 74 static FilterFactory* CreateFactory(const MockFilterConfig* config) {
73 return new FilterFactoryImpl1<MockDataSource, 75 return new FilterFactoryImpl1<MockDataSource,
74 const MockFilterConfig*>(config); 76 const MockFilterConfig*>(config);
75 } 77 }
76 78
77 explicit MockDataSource(const MockFilterConfig* config) 79 explicit MockDataSource(const MockFilterConfig* config)
78 : config_(config), 80 : config_(config),
79 position_(0) { 81 position_(0),
82 deleted_(NULL) {
83 }
84
85 MockDataSource(const MockFilterConfig* config, bool* deleted)
86 : config_(config),
87 position_(0),
88 deleted_(deleted) {
89 EXPECT_TRUE(deleted);
90 EXPECT_FALSE(*deleted);
80 } 91 }
81 92
82 // Implementation of MediaFilter. 93 // Implementation of MediaFilter.
83 virtual void Stop() {} 94 virtual void Stop() {}
84 95
85 // Implementation of DataSource. 96 // Implementation of DataSource.
86 virtual bool Initialize(const std::string& url) { 97 virtual bool Initialize(const std::string& url) {
87 media_format_.SetAsString(MediaFormat::kMimeType, 98 media_format_.SetAsString(MediaFormat::kMimeType,
88 mime_type::kApplicationOctetStream); 99 mime_type::kApplicationOctetStream);
89 media_format_.SetAsString(MediaFormat::kURL, url); 100 media_format_.SetAsString(MediaFormat::kURL, url);
(...skipping 24 matching lines...) Expand all
114 125
115 virtual const MediaFormat* GetMediaFormat() { 126 virtual const MediaFormat* GetMediaFormat() {
116 return &media_format_; 127 return &media_format_;
117 } 128 }
118 129
119 virtual size_t Read(uint8* data, size_t size) { 130 virtual size_t Read(uint8* data, size_t size) {
120 size_t read = static_cast<size_t>(config_->media_total_bytes - position_); 131 size_t read = static_cast<size_t>(config_->media_total_bytes - position_);
121 if (size < read) { 132 if (size < read) {
122 read = size; 133 read = size;
123 } 134 }
124 memset(data, 0, read); 135 memset(data, config_->data_source_value, read);
125 return read; 136 return read;
126 } 137 }
127 138
128 virtual bool GetPosition(int64* position_out) { 139 virtual bool GetPosition(int64* position_out) {
129 *position_out = position_; 140 *position_out = position_;
130 return true; 141 return true;
131 } 142 }
132 143
133 virtual bool SetPosition(int64 position) { 144 virtual bool SetPosition(int64 position) {
134 EXPECT_GE(position, 0u);
135 EXPECT_LE(position, config_->media_total_bytes);
136 if (position < 0u || position > config_->media_total_bytes) { 145 if (position < 0u || position > config_->media_total_bytes) {
137 return false; 146 return false;
138 } 147 }
139 position_ = position; 148 position_ = position;
140 return true; 149 return true;
141 } 150 }
142 151
143 virtual bool GetSize(int64* size_out) { 152 virtual bool GetSize(int64* size_out) {
144 *size_out = config_->media_total_bytes; 153 if (config_->media_total_bytes >= 0) {
154 *size_out = config_->media_total_bytes;
155 return true;
156 }
145 return false; 157 return false;
146 } 158 }
147 159
160 // Simple position getter for unit testing.
161 int64 position() const { return position_; }
162
148 private: 163 private:
149 virtual ~MockDataSource() {} 164 virtual ~MockDataSource() {
165 if (deleted_) {
166 *deleted_ = true;
167 }
168 }
150 169
151 void TaskBehavior() { 170 void TaskBehavior() {
152 switch (config_->data_source_behavior) { 171 switch (config_->data_source_behavior) {
153 case MOCK_DATA_SOURCE_TASK_ERROR_POST_INIT: 172 case MOCK_DATA_SOURCE_TASK_ERROR_POST_INIT:
154 case MOCK_DATA_SOURCE_TASK_ERROR_PRE_INIT: 173 case MOCK_DATA_SOURCE_TASK_ERROR_PRE_INIT:
155 host_->Error(PIPELINE_ERROR_NETWORK); 174 host_->Error(PIPELINE_ERROR_NETWORK);
156 break; 175 break;
157 case MOCK_DATA_SOURCE_TASK_INIT: 176 case MOCK_DATA_SOURCE_TASK_INIT:
158 host_->InitializationComplete(); 177 host_->InitializationComplete();
159 break; 178 break;
160 default: 179 default:
161 NOTREACHED(); 180 NOTREACHED();
162 } 181 }
163 } 182 }
164 183
165 const MockFilterConfig* config_; 184 const MockFilterConfig* config_;
166 int64 position_; 185 int64 position_;
167 MediaFormat media_format_; 186 MediaFormat media_format_;
168 187
188 // Set to true inside the destructor. Used in FFmpegGlue unit tests for
189 // testing proper reference counting.
190 bool* deleted_;
191
169 DISALLOW_COPY_AND_ASSIGN(MockDataSource); 192 DISALLOW_COPY_AND_ASSIGN(MockDataSource);
170 }; 193 };
171 194
172 //------------------------------------------------------------------------------ 195 //------------------------------------------------------------------------------
173 196
174 class MockDemuxer : public Demuxer { 197 class MockDemuxer : public Demuxer {
175 public: 198 public:
176 static FilterFactory* CreateFactory(const MockFilterConfig* config) { 199 static FilterFactory* CreateFactory(const MockFilterConfig* config) {
177 return new FilterFactoryImpl1<MockDemuxer, 200 return new FilterFactoryImpl1<MockDemuxer,
178 const MockFilterConfig*>(config); 201 const MockFilterConfig*>(config);
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 base::WaitableEvent event_; 617 base::WaitableEvent event_;
595 bool callback_success_status_; 618 bool callback_success_status_;
596 bool waiting_for_callback_; 619 bool waiting_for_callback_;
597 620
598 DISALLOW_COPY_AND_ASSIGN(InitializationHelper); 621 DISALLOW_COPY_AND_ASSIGN(InitializationHelper);
599 }; 622 };
600 623
601 } // namespace media 624 } // namespace media
602 625
603 #endif // MEDIA_BASE_MOCK_MEDIA_FILTERS_H_ 626 #endif // MEDIA_BASE_MOCK_MEDIA_FILTERS_H_
OLDNEW
« no previous file with comments | « media/DEPS ('k') | media/base/pipeline.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698