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

Unified Diff: media/mojo/services/mojo_source_buffer_service.cc

Issue 2643743002: Mojify demuxers and allow running {Chunk/FFmpeg}Demuxer in a Utility Process (Closed)
Patch Set: Rebase and make sure to unbind mojom::DemuxerPtr on the bound thread during termination Created 3 years, 10 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/mojo/services/mojo_source_buffer_service.h ('k') | media/mojo/services/utility_mojo_media_client.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/mojo/services/mojo_source_buffer_service.cc
diff --git a/media/mojo/services/mojo_source_buffer_service.cc b/media/mojo/services/mojo_source_buffer_service.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d654ad391ed38a4e29e1c2f038ccae6f8a6acc6a
--- /dev/null
+++ b/media/mojo/services/mojo_source_buffer_service.cc
@@ -0,0 +1,217 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "media/mojo/services/mojo_source_buffer_service.h"
+
+#include <map>
+
+#include "media/base/data_buffer.h"
+#include "media/base/media_tracks.h"
+#include "media/base/source_buffer.h"
+#include "media/mojo/common/media_type_converters.h"
+#include "media/mojo/common/mojo_data_buffer_converter.h"
+
+namespace media {
+
+MojoSourceBufferService::MojoSourceBufferService(
+ base::WeakPtr<MojoDemuxerServiceContext> context)
+ : task_runner_(base::ThreadTaskRunnerHandle::Get()),
+ context_(context),
+ source_buffer_(nullptr),
+ weak_factory_(this) {
+ DCHECK(context_);
+}
+
+MojoSourceBufferService::~MojoSourceBufferService() {}
+
+void MojoSourceBufferService::Initialize(
+ mojom::SourceBufferClientAssociatedPtrInfo client,
+ int32_t demuxer_id,
+ mojo::ScopedDataPipeConsumerHandle consumer_handle) {
+ CHECK(task_runner_->BelongsToCurrentThread());
+
+ client_.Bind(std::move(client));
+
+ context_->GetDemuxerSourceBuffer(demuxer_id, &source_buffer_);
+ CHECK(source_buffer_);
+
+ mojo_data_buffer_reader_.reset(
+ new MojoDataBufferReader(std::move(consumer_handle)));
+}
+
+void MojoSourceBufferService::AddId(const std::string& id,
+ const std::string& type,
+ const std::string& codecs,
+ const AddIdCallback& callback) {
+ CHECK(task_runner_->BelongsToCurrentThread());
+ media::SourceBuffer::Status status = source_buffer_->AddId(id, type, codecs);
+ callback.Run(status);
+}
+
+void MojoSourceBufferService::AppendData(const std::string& id,
+ mojom::DataBufferPtr mojo_data_buffer,
+ base::TimeDelta append_window_start,
+ base::TimeDelta append_window_end,
+ const AppendDataCallback& callback) {
+ CHECK(task_runner_->BelongsToCurrentThread());
+
+ mojo_data_buffer_reader_->ReadDataBuffer(
+ std::move(mojo_data_buffer),
+ base::BindOnce(&MojoSourceBufferService::OnBufferRead,
+ weak_factory_.GetWeakPtr(), id, append_window_start,
+ append_window_end, callback));
+}
+
+void MojoSourceBufferService::OnBufferRead(const std::string& id,
+ base::TimeDelta append_window_start,
+ base::TimeDelta append_window_end,
+ const AppendDataCallback& callback,
+ scoped_refptr<DataBuffer> buffer) {
+ CHECK(task_runner_->BelongsToCurrentThread());
+ base::TimeDelta timestamp_offset;
+ bool success = false;
+
+ if (!buffer) {
+ callback.Run(success, timestamp_offset);
+ return;
+ }
+ success = source_buffer_->AppendData(id, buffer->data(), buffer->data_size(),
+ append_window_start, append_window_end,
+ &timestamp_offset);
+ callback.Run(success, timestamp_offset);
+}
+
+void MojoSourceBufferService::SetTracksWatcher(const std::string& id) {
+ CHECK(task_runner_->BelongsToCurrentThread());
+ source_buffer_->SetTracksWatcher(
+ id, base::Bind(&MojoSourceBufferService::OnTracksWatcher,
+ weak_factory_.GetWeakPtr(), id));
+}
+
+void MojoSourceBufferService::OnTracksWatcher(
+ const std::string& id,
+ std::unique_ptr<MediaTracks> tracks) {
+ CHECK(task_runner_->BelongsToCurrentThread());
+ CHECK(tracks);
+ mojom::MediaTracksPtr mojo_tracks = mojom::MediaTracks::From(*tracks.get());
+ CHECK(mojo_tracks);
+
+ client_->OnTracksWatcher(id, std::move(mojo_tracks));
+}
+
+void MojoSourceBufferService::RemoveId(const std::string& id) {
+ CHECK(task_runner_->BelongsToCurrentThread());
+ source_buffer_->RemoveId(id);
+}
+
+void MojoSourceBufferService::GetBufferedRanges(
+ const std::string& id,
+ const GetBufferedRangesCallback& callback) {
+ CHECK(task_runner_->BelongsToCurrentThread());
+ Ranges<base::TimeDelta> ranges = source_buffer_->GetBufferedRanges(id);
+ mojom::RangesTimeDeltaPtr mojo_ranges = mojom::RangesTimeDelta::From(ranges);
+ CHECK(mojo_ranges);
+ callback.Run(std::move(mojo_ranges));
+}
+
+void MojoSourceBufferService::GetHighestPresentationTimestamp(
+ const std::string& id,
+ const GetHighestPresentationTimestampCallback& callback) {
+ CHECK(task_runner_->BelongsToCurrentThread());
+ base::TimeDelta timestamp =
+ source_buffer_->GetHighestPresentationTimestamp(id);
+ callback.Run(timestamp);
+}
+
+void MojoSourceBufferService::ResetParserState(
+ const std::string& id,
+ base::TimeDelta append_window_start,
+ base::TimeDelta append_window_end,
+ const ResetParserStateCallback& callback) {
+ CHECK(task_runner_->BelongsToCurrentThread());
+ base::TimeDelta timestamp_offset;
+ source_buffer_->ResetParserState(id, append_window_start, append_window_end,
+ &timestamp_offset);
+ callback.Run(timestamp_offset);
+}
+
+void MojoSourceBufferService::Remove(const std::string& id,
+ base::TimeDelta start,
+ base::TimeDelta end) {
+ CHECK(task_runner_->BelongsToCurrentThread());
+ source_buffer_->Remove(id, start, end);
+}
+
+void MojoSourceBufferService::EvictCodedFrames(
+ const std::string& id,
+ base::TimeDelta currentMediaTime,
+ size_t newDataSize,
+ const EvictCodedFramesCallback& callback) {
+ CHECK(task_runner_->BelongsToCurrentThread());
+ bool success =
+ source_buffer_->EvictCodedFrames(id, currentMediaTime, newDataSize);
+ callback.Run(success);
+}
+
+void MojoSourceBufferService::OnMemoryPressure(
+ base::TimeDelta currentMediaTime,
+ base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level,
+ bool force_instant_gc) {
+ CHECK(task_runner_->BelongsToCurrentThread());
+ source_buffer_->OnMemoryPressure(currentMediaTime, memory_pressure_level,
+ force_instant_gc);
+}
+
+void MojoSourceBufferService::GetDuration(const GetDurationCallback& callback) {
+ double duration = source_buffer_->GetDuration();
+ callback.Run(duration);
+}
+
+void MojoSourceBufferService::GetDuration_Locked(
+ const GetDuration_LockedCallback& callback) {
+ callback.Run(source_buffer_->GetDuration_Locked());
+}
+
+void MojoSourceBufferService::SetDuration(double duration) {
+ source_buffer_->SetDuration(duration);
+}
+
+void MojoSourceBufferService::IsParsingMediaSegment(
+ const std::string& id,
+ const IsParsingMediaSegmentCallback& callback) {
+ bool is_parsing = source_buffer_->IsParsingMediaSegment(id);
+ callback.Run(is_parsing);
+}
+
+void MojoSourceBufferService::SetSequenceMode(const std::string& id,
+ bool sequence_mode) {
+ source_buffer_->SetSequenceMode(id, sequence_mode);
+}
+
+void MojoSourceBufferService::SetGroupStartTimestampIfInSequenceMode(
+ const std::string& id,
+ base::TimeDelta timestamp_offset) {
+ source_buffer_->SetGroupStartTimestampIfInSequenceMode(id, timestamp_offset);
+}
+
+void MojoSourceBufferService::MarkEndOfStream(PipelineStatus status) {
+ source_buffer_->MarkEndOfStream(status);
+}
+
+void MojoSourceBufferService::UnmarkEndOfStream() {
+ source_buffer_->UnmarkEndOfStream();
+}
+
+void MojoSourceBufferService::Shutdown() {
+ source_buffer_->Shutdown();
+}
+/*
+void MojoSourceBufferService::SetMemoryLimitsForTest(DemuxerStream::Type type,
+size_t memory_limit){}
+
+Ranges<base::TimeDelta> MojoSourceBufferService::GetBufferedRanges() const{
+ return source_buffer_->GetBufferedRanges();
+}*/
+
+} // namespace media
« no previous file with comments | « media/mojo/services/mojo_source_buffer_service.h ('k') | media/mojo/services/utility_mojo_media_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698