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

Unified Diff: media/filters/chunk_demuxer.cc

Issue 10803019: Chrome-side implementation of media source timestamp offset (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move logic from parser to demuxer Created 8 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 side-by-side diff with in-line comments
Download patch
Index: media/filters/chunk_demuxer.cc
diff --git a/media/filters/chunk_demuxer.cc b/media/filters/chunk_demuxer.cc
index 06a8d62923e6fa9d98e90db81d32968681a404b6..d90052876629057ed7479e71744afd14efe3ed82 100644
--- a/media/filters/chunk_demuxer.cc
+++ b/media/filters/chunk_demuxer.cc
@@ -99,7 +99,7 @@ static bool IsSupported(const std::string& type,
*has_audio = false;
*has_video = false;
- // Search for the SupportedTypeInfo for |type|
+ // Search for the SupportedTypeInfo for |type|.
for (size_t i = 0; i < arraysize(kSupportedTypeInfo); ++i) {
const SupportedTypeInfo& type_info = kSupportedTypeInfo[i];
if (type == type_info.type) {
@@ -465,6 +465,20 @@ void ChunkDemuxerStream::CreateReadDoneClosures_Locked(ClosureQueue* closures) {
}
}
+void ChunkDemuxer::AdjustBufferTimestamps(
+ const StreamParser::BufferQueue& buffers,
+ base::TimeDelta timestamp_offset) {
+ if (timestamp_offset == base::TimeDelta())
+ return;
+
+ for (StreamParser::BufferQueue::const_iterator itr = buffers.begin();
+ itr != buffers.end(); ++itr) {
+ (*itr)->SetDecodeTimestamp(
+ (*itr)->GetDecodeTimestamp() + timestamp_offset);
+ (*itr)->SetTimestamp((*itr)->GetTimestamp() + timestamp_offset);
+ }
+}
+
ChunkDemuxer::ChunkDemuxer(ChunkDemuxerClient* client)
: state_(WAITING_FOR_INIT),
host_(NULL),
@@ -611,9 +625,13 @@ ChunkDemuxer::Status ChunkDemuxer::AddId(const std::string& id,
audio_cb,
video_cb,
base::Bind(&ChunkDemuxer::OnNeedKey, base::Unretained(this)),
- base::Bind(&ChunkDemuxer::OnNewMediaSegment, base::Unretained(this), id));
+ base::Bind(&ChunkDemuxer::OnNewMediaSegment, base::Unretained(this), id),
+ base::Bind(&ChunkDemuxer::OnEndOfMediaSegment,
+ base::Unretained(this), id));
stream_parser_map_[id] = stream_parser.release();
+ StreamInfo info = { base::TimeDelta(), true };
+ stream_info_map_[id] = info;
return kOk;
}
@@ -624,6 +642,7 @@ void ChunkDemuxer::RemoveId(const std::string& id) {
delete stream_parser_map_[id];
stream_parser_map_.erase(id);
+ stream_info_map_.erase(id);
if (source_id_audio_ == id && audio_)
audio_->Shutdown();
@@ -759,6 +778,20 @@ void ChunkDemuxer::Abort(const std::string& id) {
stream_parser_map_[id]->Flush();
}
+bool ChunkDemuxer::TimestampOffset(const std::string& id, float offset) {
+ DVLOG(1) << "TimestampOffset(" << id << ", " << offset << ")";
+ DCHECK_GT(stream_parser_map_.count(id), 0u);
+
+ TimeDelta time_offset = TimeDelta::FromMicroseconds(
+ offset * base::Time::kMicrosecondsPerSecond);
+
+ if (!stream_info_map_[id].can_update_offset)
+ return false;
+
+ stream_info_map_[id].timestamp_offset = time_offset;
+ return true;
+}
+
bool ChunkDemuxer::EndOfStream(PipelineStatus status) {
DVLOG(1) << "EndOfStream(" << status << ")";
base::AutoLock auto_lock(lock_);
@@ -963,6 +996,11 @@ bool ChunkDemuxer::OnAudioBuffers(const StreamParser::BufferQueue& buffers) {
if (!audio_)
return false;
+ CHECK_GT(stream_info_map_.count(source_id_audio_), 0u);
+ AdjustBufferTimestamps(
+ buffers, stream_info_map_[source_id_audio_].timestamp_offset);
+ stream_info_map_[source_id_video_].can_update_offset = false;
acolwell GONE FROM CHROMIUM 2012/07/20 18:21:01 did you mean source_id_audio_ here?
vrk (LEFT CHROMIUM) 2012/07/25 17:16:48 d'oh. Yes :) My test page only uses video, so I di
+
return audio_->Append(buffers);
}
@@ -973,6 +1011,11 @@ bool ChunkDemuxer::OnVideoBuffers(const StreamParser::BufferQueue& buffers) {
if (!video_)
return false;
+ CHECK_GT(stream_info_map_.count(source_id_video_), 0u);
+ AdjustBufferTimestamps(
+ buffers, stream_info_map_[source_id_video_].timestamp_offset);
+ stream_info_map_[source_id_video_].can_update_offset = false;
acolwell GONE FROM CHROMIUM 2012/07/20 18:21:01 Perhaps move this to OnNewMediaSegment()? That way
vrk (LEFT CHROMIUM) 2012/07/25 17:16:48 Done and removed from OnAudioBuffers() as well.
+
return video_->Append(buffers);
}
@@ -983,11 +1026,15 @@ bool ChunkDemuxer::OnNeedKey(scoped_array<uint8> init_data,
}
void ChunkDemuxer::OnNewMediaSegment(const std::string& source_id,
- TimeDelta start_timestamp) {
+ TimeDelta timestamp) {
DVLOG(2) << "OnNewMediaSegment(" << source_id << ", "
- << start_timestamp.InSecondsF() << ")";
+ << timestamp.InSecondsF() << ")";
lock_.AssertAcquired();
+ CHECK_GT(stream_info_map_.count(source_id), 0u);
+ base::TimeDelta start_timestamp =
+ timestamp + stream_info_map_[source_id].timestamp_offset;
+
if (start_time_ == kNoTimestamp()) {
DCHECK(state_ == INITIALIZING || state_ == WAITING_FOR_START_TIME);
// Use the first reported media segment start time as the |start_time_|
@@ -1017,4 +1064,10 @@ void ChunkDemuxer::OnNewMediaSegment(const std::string& source_id,
base::ResetAndReturn(&init_cb_).Run(PIPELINE_OK);
}
+void ChunkDemuxer::OnEndOfMediaSegment(const std::string& source_id) {
+ DVLOG(2) << "OnEndOfMediaSegment(" << source_id << ")";
+ CHECK_GT(stream_info_map_.count(source_id_video_), 0u);
+ stream_info_map_[source_id_video_].can_update_offset = true;
+}
+
} // namespace media

Powered by Google App Engine
This is Rietveld 408576698