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

Unified Diff: media/webm/webm_stream_parser.cc

Issue 10205004: Refactoring StreamParser & StreamParserHost interfaces. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix minor lint errors Created 8 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/webm/webm_stream_parser.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/webm/webm_stream_parser.cc
diff --git a/media/webm/webm_stream_parser.cc b/media/webm/webm_stream_parser.cc
index d986deb0b6815449b30a25489c2a1369d1390d96..c0b01fcb1a57c052f48de98b16bc1d535a2ccd9e 100644
--- a/media/webm/webm_stream_parser.cc
+++ b/media/webm/webm_stream_parser.cc
@@ -181,43 +181,76 @@ bool FFmpegConfigHelper::SetupStreamConfigs() {
}
WebMStreamParser::WebMStreamParser()
- : state_(WAITING_FOR_INIT),
+ : state_(kWaitingForInit),
host_(NULL) {
}
WebMStreamParser::~WebMStreamParser() {}
void WebMStreamParser::Init(const InitCB& init_cb, StreamParserHost* host) {
- DCHECK_EQ(state_, WAITING_FOR_INIT);
+ DCHECK_EQ(state_, kWaitingForInit);
DCHECK(init_cb_.is_null());
DCHECK(!host_);
DCHECK(!init_cb.is_null());
DCHECK(host);
- ChangeState(PARSING_HEADERS);
+ ChangeState(kParsingHeaders);
init_cb_ = init_cb;
host_ = host;
}
void WebMStreamParser::Flush() {
- DCHECK_NE(state_, WAITING_FOR_INIT);
+ DCHECK_NE(state_, kWaitingForInit);
- if (state_ != PARSING_CLUSTERS)
+ byte_queue_.Reset();
+
+ if (state_ != kParsingClusters)
return;
cluster_parser_->Reset();
}
-int WebMStreamParser::Parse(const uint8* buf, int size) {
- DCHECK_NE(state_, WAITING_FOR_INIT);
+bool WebMStreamParser::Parse(const uint8* buf, int size) {
+ DCHECK_NE(state_, kWaitingForInit);
+
+ if (state_ == kError)
+ return false;
- if (state_ == PARSING_HEADERS)
- return ParseInfoAndTracks(buf, size);
+ byte_queue_.Push(buf, size);
- if (state_ == PARSING_CLUSTERS)
- return ParseCluster(buf, size);
+ int result = 0;
+ int bytes_parsed = 0;
+ const uint8* cur = NULL;
+ int cur_size = 0;
+
+ byte_queue_.Peek(&cur, &cur_size);
+ do {
+ switch (state_) {
+ case kParsingHeaders:
+ result = ParseInfoAndTracks(cur, cur_size);
+ break;
+
+ case kParsingClusters:
+ result = ParseCluster(cur, cur_size);
+ break;
+
+ case kWaitingForInit:
+ case kError:
+ return false;
+ }
- return -1;
+ if (result < 0) {
+ ChangeState(kError);
+ return false;
+ }
+
+ cur += result;
+ cur_size -= result;
+ bytes_parsed += result;
+ } while (result > 0 && cur_size > 0);
+
+ byte_queue_.Pop(bytes_parsed);
+ return true;
}
void WebMStreamParser::ChangeState(State new_state) {
@@ -295,11 +328,8 @@ int WebMStreamParser::ParseInfoAndTracks(const uint8* data, int size) {
if (!config_helper.Parse(data, bytes_parsed))
return -1;
- if (config_helper.audio_config().IsValidConfig())
- host_->OnNewAudioConfig(config_helper.audio_config());
-
- if (config_helper.video_config().IsValidConfig())
- host_->OnNewVideoConfig(config_helper.video_config());
+ host_->OnNewConfigs(config_helper.audio_config(),
+ config_helper.video_config());
cluster_parser_.reset(new WebMClusterParser(
info_parser.timecode_scale(),
@@ -310,7 +340,7 @@ int WebMStreamParser::ParseInfoAndTracks(const uint8* data, int size) {
tracks_parser.video_encryption_key_id(),
tracks_parser.video_encryption_key_id_size()));
- ChangeState(PARSING_CLUSTERS);
+ ChangeState(kParsingClusters);
init_cb_.Run(true, duration);
init_cb_.Reset();
« no previous file with comments | « media/webm/webm_stream_parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698