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

Unified Diff: media/mojo/common/mojo_data_buffer_converter.h

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/common/media_type_converters.cc ('k') | media/mojo/common/mojo_data_buffer_converter.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/mojo/common/mojo_data_buffer_converter.h
diff --git a/media/mojo/common/mojo_data_buffer_converter.h b/media/mojo/common/mojo_data_buffer_converter.h
new file mode 100644
index 0000000000000000000000000000000000000000..40287a250cabf96eb38896e47048015268964656
--- /dev/null
+++ b/media/mojo/common/mojo_data_buffer_converter.h
@@ -0,0 +1,96 @@
+// 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.
+
+#ifndef MEDIA_MOJO_COMMON_MOJO_DATA_BUFFER_CONVERTER_
+#define MEDIA_MOJO_COMMON_MOJO_DATA_BUFFER_CONVERTER_
+
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "media/mojo/interfaces/media_types.mojom.h"
+#include "mojo/public/cpp/system/data_pipe.h"
+#include "mojo/public/cpp/system/watcher.h"
+
+namespace media {
+
+class DataBuffer;
+
+// A helper class that converts mojom::DataBuffer to media::DataBuffer.
+// The data part of the DataBuffer is read from a DataPipe.
+class MojoDataBufferReader {
+ public:
+ using ReadCB = base::OnceCallback<void(scoped_refptr<DataBuffer>)>;
+
+ // Creates a MojoDataBufferReader of |type| and set the |producer_handle|.
+ static std::unique_ptr<MojoDataBufferReader> Create(
+ uint32_t capacity_num_bytes,
+ mojo::ScopedDataPipeProducerHandle* producer_handle);
+
+ // Hold the consumer handle to read DataBuffer data.
+ explicit MojoDataBufferReader(
+ mojo::ScopedDataPipeConsumerHandle consumer_handle);
+
+ ~MojoDataBufferReader();
+
+ // Converts |buffer| into a DataBuffer (read data from DataPipe if needed).
+ // |read_cb| is called with the result DataBuffer.
+ // Reports a null DataBuffer in case of an error.
+ void ReadDataBuffer(mojom::DataBufferPtr buffer, ReadCB read_cb);
+
+ private:
+ void OnPipeError(MojoResult result);
+ void OnPipeReadable(MojoResult result);
+ void ReadDataBufferData();
+
+ // For reading the data section of a DataBuffer.
+ mojo::ScopedDataPipeConsumerHandle consumer_handle_;
+ mojo::Watcher pipe_watcher_;
+
+ // Only valid during pending read.
+ ReadCB read_cb_;
+ scoped_refptr<DataBuffer> media_buffer_;
+ uint32_t bytes_read_;
+
+ DISALLOW_COPY_AND_ASSIGN(MojoDataBufferReader);
+};
+
+// A helper class that converts media::DataBuffer to mojom::DataBuffer.
+// The data part of the DataBuffer is written into a DataPipe.
+class MojoDataBufferWriter {
+ public:
+ // Creates a MojoDataBufferWriter of |type| and set the |consumer_handle|.
+ static std::unique_ptr<MojoDataBufferWriter> Create(
+ uint32_t capacity_num_bytes,
+ mojo::ScopedDataPipeConsumerHandle* consumer_handle);
+
+ // Hold the producer handle to write DataBuffer data.
+ explicit MojoDataBufferWriter(
+ mojo::ScopedDataPipeProducerHandle producer_handle);
+
+ ~MojoDataBufferWriter();
+
+ // Converts a DataBuffer into mojo DataBuffer.
+ // DataBuffer data is asynchronously written into DataPipe if needed.
+ // Returns null if conversion failed or if the data pipe is already closed.
+ mojom::DataBufferPtr WriteDataBuffer(
+ const scoped_refptr<DataBuffer>& media_buffer);
+
+ private:
+ void OnPipeError(MojoResult result);
+ void OnPipeWritable(MojoResult result);
+ MojoResult WriteDataBufferData();
+
+ // For writing the data section of DataBuffer into DataPipe.
+ mojo::ScopedDataPipeProducerHandle producer_handle_;
+ mojo::Watcher pipe_watcher_;
+
+ // Only valid when data is being written to the pipe.
+ scoped_refptr<DataBuffer> media_buffer_;
+ uint32_t bytes_written_;
+
+ DISALLOW_COPY_AND_ASSIGN(MojoDataBufferWriter);
+};
+
+} // namespace media
+
+#endif // MEDIA_MOJO_COMMON_MOJO_DATA_BUFFER_CONVERTER_
« no previous file with comments | « media/mojo/common/media_type_converters.cc ('k') | media/mojo/common/mojo_data_buffer_converter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698