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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef MEDIA_MOJO_COMMON_MOJO_DATA_BUFFER_CONVERTER_
6 #define MEDIA_MOJO_COMMON_MOJO_DATA_BUFFER_CONVERTER_
7
8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h"
10 #include "media/mojo/interfaces/media_types.mojom.h"
11 #include "mojo/public/cpp/system/data_pipe.h"
12 #include "mojo/public/cpp/system/watcher.h"
13
14 namespace media {
15
16 class DataBuffer;
17
18 // A helper class that converts mojom::DataBuffer to media::DataBuffer.
19 // The data part of the DataBuffer is read from a DataPipe.
20 class MojoDataBufferReader {
21 public:
22 using ReadCB = base::OnceCallback<void(scoped_refptr<DataBuffer>)>;
23
24 // Creates a MojoDataBufferReader of |type| and set the |producer_handle|.
25 static std::unique_ptr<MojoDataBufferReader> Create(
26 uint32_t capacity_num_bytes,
27 mojo::ScopedDataPipeProducerHandle* producer_handle);
28
29 // Hold the consumer handle to read DataBuffer data.
30 explicit MojoDataBufferReader(
31 mojo::ScopedDataPipeConsumerHandle consumer_handle);
32
33 ~MojoDataBufferReader();
34
35 // Converts |buffer| into a DataBuffer (read data from DataPipe if needed).
36 // |read_cb| is called with the result DataBuffer.
37 // Reports a null DataBuffer in case of an error.
38 void ReadDataBuffer(mojom::DataBufferPtr buffer, ReadCB read_cb);
39
40 private:
41 void OnPipeError(MojoResult result);
42 void OnPipeReadable(MojoResult result);
43 void ReadDataBufferData();
44
45 // For reading the data section of a DataBuffer.
46 mojo::ScopedDataPipeConsumerHandle consumer_handle_;
47 mojo::Watcher pipe_watcher_;
48
49 // Only valid during pending read.
50 ReadCB read_cb_;
51 scoped_refptr<DataBuffer> media_buffer_;
52 uint32_t bytes_read_;
53
54 DISALLOW_COPY_AND_ASSIGN(MojoDataBufferReader);
55 };
56
57 // A helper class that converts media::DataBuffer to mojom::DataBuffer.
58 // The data part of the DataBuffer is written into a DataPipe.
59 class MojoDataBufferWriter {
60 public:
61 // Creates a MojoDataBufferWriter of |type| and set the |consumer_handle|.
62 static std::unique_ptr<MojoDataBufferWriter> Create(
63 uint32_t capacity_num_bytes,
64 mojo::ScopedDataPipeConsumerHandle* consumer_handle);
65
66 // Hold the producer handle to write DataBuffer data.
67 explicit MojoDataBufferWriter(
68 mojo::ScopedDataPipeProducerHandle producer_handle);
69
70 ~MojoDataBufferWriter();
71
72 // Converts a DataBuffer into mojo DataBuffer.
73 // DataBuffer data is asynchronously written into DataPipe if needed.
74 // Returns null if conversion failed or if the data pipe is already closed.
75 mojom::DataBufferPtr WriteDataBuffer(
76 const scoped_refptr<DataBuffer>& media_buffer);
77
78 private:
79 void OnPipeError(MojoResult result);
80 void OnPipeWritable(MojoResult result);
81 MojoResult WriteDataBufferData();
82
83 // For writing the data section of DataBuffer into DataPipe.
84 mojo::ScopedDataPipeProducerHandle producer_handle_;
85 mojo::Watcher pipe_watcher_;
86
87 // Only valid when data is being written to the pipe.
88 scoped_refptr<DataBuffer> media_buffer_;
89 uint32_t bytes_written_;
90
91 DISALLOW_COPY_AND_ASSIGN(MojoDataBufferWriter);
92 };
93
94 } // namespace media
95
96 #endif // MEDIA_MOJO_COMMON_MOJO_DATA_BUFFER_CONVERTER_
OLDNEW
« 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