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

Side by Side Diff: media/filters/source_buffer.cc

Issue 10389125: Refactor StreamParser creation & enforce configs matching expected stream types. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 7 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/filters/source_buffer.h ('k') | no next file » | 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) 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 "media/filters/source_buffer.h" 5 #include "media/filters/source_buffer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "media/webm/webm_stream_parser.h" 9 #include "media/webm/webm_stream_parser.h"
10 10
11 namespace media { 11 namespace media {
12 12
13 SourceBuffer::SourceBuffer() {} 13 SourceBuffer::SourceBuffer() {}
14 14
15 SourceBuffer::~SourceBuffer() {} 15 SourceBuffer::~SourceBuffer() {}
16 16
17 void SourceBuffer::Init(const InitCB& init_cb, 17 void SourceBuffer::Init(scoped_ptr<StreamParser> parser,
18 const InitCB& init_cb,
18 const NewConfigCB& config_cb, 19 const NewConfigCB& config_cb,
19 const NewBuffersCB& audio_cb, 20 const NewBuffersCB& audio_cb,
20 const NewBuffersCB& video_cb, 21 const NewBuffersCB& video_cb,
21 const KeyNeededCB& key_needed_cb) { 22 const KeyNeededCB& key_needed_cb) {
22 DCHECK(init_cb_.is_null()); 23 DCHECK(init_cb_.is_null());
24 DCHECK(parser.get());
23 DCHECK(!init_cb.is_null()); 25 DCHECK(!init_cb.is_null());
24 DCHECK(!config_cb.is_null()); 26 DCHECK(!config_cb.is_null());
25 DCHECK(!audio_cb.is_null() || !video_cb.is_null()); 27 DCHECK(!audio_cb.is_null() || !video_cb.is_null());
26 DCHECK(!key_needed_cb.is_null()); 28 DCHECK(!key_needed_cb.is_null());
27 29
28 init_cb_ = init_cb; 30 init_cb_ = init_cb;
29 config_cb_ = config_cb; 31 config_cb_ = config_cb;
30 audio_cb_ = audio_cb; 32 audio_cb_ = audio_cb;
31 video_cb_ = video_cb; 33 video_cb_ = video_cb;
32 key_needed_cb_ = key_needed_cb; 34 key_needed_cb_ = key_needed_cb;
33 35
34 stream_parser_.reset(new WebMStreamParser()); 36 stream_parser_.reset(parser.release());
35 37
36 stream_parser_->Init( 38 stream_parser_->Init(
37 base::Bind(&SourceBuffer::OnStreamParserInitDone, base::Unretained(this)), 39 base::Bind(&SourceBuffer::OnStreamParserInitDone, base::Unretained(this)),
38 base::Bind(&SourceBuffer::OnNewConfigs, base::Unretained(this)), 40 base::Bind(&SourceBuffer::OnNewConfigs, base::Unretained(this)),
39 base::Bind(&SourceBuffer::OnAudioBuffers, base::Unretained(this)), 41 base::Bind(&SourceBuffer::OnAudioBuffers, base::Unretained(this)),
40 base::Bind(&SourceBuffer::OnVideoBuffers, base::Unretained(this)), 42 base::Bind(&SourceBuffer::OnVideoBuffers, base::Unretained(this)),
41 base::Bind(&SourceBuffer::OnKeyNeeded, base::Unretained(this))); 43 base::Bind(&SourceBuffer::OnKeyNeeded, base::Unretained(this)));
42 } 44 }
43 45
44 bool SourceBuffer::AppendData(const uint8* data, size_t length) { 46 bool SourceBuffer::AppendData(const uint8* data, size_t length) {
45 return stream_parser_->Parse(data, length); 47 return stream_parser_->Parse(data, length);
46 } 48 }
47 49
48 void SourceBuffer::Flush() { 50 void SourceBuffer::Flush() {
49 stream_parser_->Flush(); 51 stream_parser_->Flush();
50 } 52 }
51 53
52 void SourceBuffer::OnStreamParserInitDone(bool success, 54 void SourceBuffer::OnStreamParserInitDone(bool success,
53 base::TimeDelta duration) { 55 base::TimeDelta duration) {
54 init_cb_.Run(success, duration); 56 init_cb_.Run(success, duration);
55 init_cb_.Reset(); 57 init_cb_.Reset();
56 } 58 }
57 59
58 bool SourceBuffer::OnNewConfigs(const AudioDecoderConfig& audio_config, 60 bool SourceBuffer::OnNewConfigs(const AudioDecoderConfig& audio_config,
59 const VideoDecoderConfig& video_config) { 61 const VideoDecoderConfig& video_config) {
60 CHECK(audio_config.IsValidConfig() || video_config.IsValidConfig()); 62 CHECK(audio_config.IsValidConfig() || video_config.IsValidConfig());
61 63
64 // Signal an error if we get configuration info for stream types
65 // we don't have a callback to handle.
66 if ((audio_config.IsValidConfig() && audio_cb_.is_null()) ||
67 (video_config.IsValidConfig() && video_cb_.is_null())) {
68 return false;
69 }
70
62 return config_cb_.Run(audio_config, video_config); 71 return config_cb_.Run(audio_config, video_config);
63 } 72 }
64 73
65 bool SourceBuffer::OnAudioBuffers(const StreamParser::BufferQueue& buffer) { 74 bool SourceBuffer::OnAudioBuffers(const StreamParser::BufferQueue& buffer) {
66 return audio_cb_.Run(buffer); 75 return audio_cb_.Run(buffer);
67 } 76 }
68 77
69 bool SourceBuffer::OnVideoBuffers(const StreamParser::BufferQueue& buffer) { 78 bool SourceBuffer::OnVideoBuffers(const StreamParser::BufferQueue& buffer) {
70 return video_cb_.Run(buffer); 79 return video_cb_.Run(buffer);
71 } 80 }
72 81
73 bool SourceBuffer::OnKeyNeeded(scoped_array<uint8> init_data, 82 bool SourceBuffer::OnKeyNeeded(scoped_array<uint8> init_data,
74 int init_data_size) { 83 int init_data_size) {
75 return key_needed_cb_.Run(init_data.Pass(), init_data_size); 84 return key_needed_cb_.Run(init_data.Pass(), init_data_size);
76 } 85 }
77 86
78 } // namespace media 87 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/source_buffer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698