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

Side by Side Diff: media/mojo/services/mojo_video_decoder_service.cc

Issue 2096063003: media: Add MojoDecoderBuffer{Reader|Writer} (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments addressed Created 4 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/mojo/services/mojo_video_decoder_service.h" 5 #include "media/mojo/services/mojo_video_decoder_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
11 #include "media/base/decoder_buffer.h" 11 #include "media/base/decoder_buffer.h"
12 #include "media/base/video_decoder.h" 12 #include "media/base/video_decoder.h"
13 #include "media/base/video_decoder_config.h" 13 #include "media/base/video_decoder_config.h"
14 #include "media/base/video_frame.h" 14 #include "media/base/video_frame.h"
15 #include "media/mojo/common/media_type_converters.h" 15 #include "media/mojo/common/media_type_converters.h"
16 #include "media/mojo/common/mojo_decoder_buffer_converter.h"
16 #include "media/mojo/services/mojo_media_client.h" 17 #include "media/mojo/services/mojo_media_client.h"
17 #include "mojo/public/c/system/types.h" 18 #include "mojo/public/c/system/types.h"
18 #include "mojo/public/cpp/system/buffer.h" 19 #include "mojo/public/cpp/system/buffer.h"
19 #include "mojo/public/cpp/system/handle.h" 20 #include "mojo/public/cpp/system/handle.h"
20 21
21 namespace media { 22 namespace media {
22 23
23 MojoVideoDecoderService::MojoVideoDecoderService( 24 MojoVideoDecoderService::MojoVideoDecoderService(
24 mojo::InterfaceRequest<mojom::VideoDecoder> request, 25 mojo::InterfaceRequest<mojom::VideoDecoder> request,
25 MojoMediaClient* mojo_media_client) 26 MojoMediaClient* mojo_media_client)
(...skipping 11 matching lines...) Expand all
37 DVLOG(1) << __FUNCTION__; 38 DVLOG(1) << __FUNCTION__;
38 39
39 if (decoder_) 40 if (decoder_)
40 return; 41 return;
41 42
42 // TODO(sandersd): Provide callback for requesting a stub. 43 // TODO(sandersd): Provide callback for requesting a stub.
43 decoder_ = mojo_media_client_->CreateVideoDecoder( 44 decoder_ = mojo_media_client_->CreateVideoDecoder(
44 base::ThreadTaskRunnerHandle::Get()); 45 base::ThreadTaskRunnerHandle::Get());
45 46
46 client_ = std::move(client); 47 client_ = std::move(client);
47 decoder_buffer_pipe_ = std::move(decoder_buffer_pipe); 48
49 mojo_decoder_buffer_reader_.reset(
50 new MojoDecoderBufferReader(std::move(decoder_buffer_pipe)));
48 } 51 }
49 52
50 void MojoVideoDecoderService::Initialize(mojom::VideoDecoderConfigPtr config, 53 void MojoVideoDecoderService::Initialize(mojom::VideoDecoderConfigPtr config,
51 bool low_delay, 54 bool low_delay,
52 const InitializeCallback& callback) { 55 const InitializeCallback& callback) {
53 DVLOG(1) << __FUNCTION__; 56 DVLOG(1) << __FUNCTION__;
54 57
55 if (!decoder_) { 58 if (!decoder_) {
56 callback.Run(false); 59 callback.Run(false);
57 return; 60 return;
(...skipping 24 matching lines...) Expand all
82 const DecodeCallback& callback) { 85 const DecodeCallback& callback) {
83 DVLOG(1) << __FUNCTION__; 86 DVLOG(1) << __FUNCTION__;
84 87
85 if (!decoder_) { 88 if (!decoder_) {
86 callback.Run(mojom::DecodeStatus::DECODE_ERROR); 89 callback.Run(mojom::DecodeStatus::DECODE_ERROR);
87 return; 90 return;
88 } 91 }
89 92
90 // TODO(sandersd): After a decode error, we should enter an error state and 93 // TODO(sandersd): After a decode error, we should enter an error state and
91 // reject all future method calls. 94 // reject all future method calls.
92 // TODO(sandersd): Extract and share with MojoAudioDecoderService. 95 // TODO(sandersd): Do not wait indefinitely.
sandersd (OOO until July 31) 2016/06/27 20:24:55 This TODO was for the implementation of reading bu
xhwang 2016/06/28 01:11:48 Done.
93 scoped_refptr<DecoderBuffer> media_buffer( 96 scoped_refptr<DecoderBuffer> media_buffer =
94 buffer.To<scoped_refptr<DecoderBuffer>>()); 97 mojo_decoder_buffer_reader_->ReadDecoderBuffer(buffer);
95 if (!media_buffer->end_of_stream()) { 98 if (!media_buffer) {
96 MojoResult result; 99 callback.Run(mojom::DecodeStatus::DECODE_ERROR);
97 MojoHandleSignalsState state; 100 return;
98
99 // TODO(sandersd): Do not wait indefinitely.
100 result =
101 MojoWait(decoder_buffer_pipe_.get().value(),
102 MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE, &state);
103 if (result != MOJO_RESULT_OK ||
104 !(state.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE)) {
105 callback.Run(mojom::DecodeStatus::DECODE_ERROR);
106 return;
107 }
108
109 uint32_t data_size = buffer->data_size;
110 uint32_t bytes_read = data_size;
111 DCHECK_EQ(data_size, media_buffer->data_size());
112 result =
113 ReadDataRaw(decoder_buffer_pipe_.get(), media_buffer->writable_data(),
114 &bytes_read, MOJO_READ_DATA_FLAG_ALL_OR_NONE);
115 if (result != MOJO_RESULT_OK || bytes_read != data_size) {
116 callback.Run(mojom::DecodeStatus::DECODE_ERROR);
117 return;
118 }
119 } 101 }
120 102
121 decoder_->Decode(media_buffer, 103 decoder_->Decode(media_buffer,
122 base::Bind(&MojoVideoDecoderService::OnDecoderDecoded, 104 base::Bind(&MojoVideoDecoderService::OnDecoderDecoded,
123 weak_this_, callback)); 105 weak_this_, callback));
124 } 106 }
125 107
126 void MojoVideoDecoderService::OnDecoderDecoded(const DecodeCallback& callback, 108 void MojoVideoDecoderService::OnDecoderDecoded(const DecodeCallback& callback,
127 DecodeStatus status) { 109 DecodeStatus status) {
128 DVLOG(1) << __FUNCTION__; 110 DVLOG(1) << __FUNCTION__;
(...skipping 11 matching lines...) Expand all
140 decoder_->Reset(base::Bind(&MojoVideoDecoderService::OnDecoderReset, 122 decoder_->Reset(base::Bind(&MojoVideoDecoderService::OnDecoderReset,
141 weak_this_, callback)); 123 weak_this_, callback));
142 } 124 }
143 125
144 void MojoVideoDecoderService::OnDecoderReset(const ResetCallback& callback) { 126 void MojoVideoDecoderService::OnDecoderReset(const ResetCallback& callback) {
145 DVLOG(1) << __FUNCTION__; 127 DVLOG(1) << __FUNCTION__;
146 callback.Run(); 128 callback.Run();
147 } 129 }
148 130
149 } // namespace media 131 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698