OLD | NEW |
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/common/mojo_decoder_buffer_converter.h" |
| 17 #include "media/mojo/common/mojo_shared_buffer_video_frame.h" |
17 #include "media/mojo/services/mojo_media_client.h" | 18 #include "media/mojo/services/mojo_media_client.h" |
18 #include "mojo/public/c/system/types.h" | 19 #include "mojo/public/c/system/types.h" |
19 #include "mojo/public/cpp/system/buffer.h" | 20 #include "mojo/public/cpp/system/buffer.h" |
20 #include "mojo/public/cpp/system/handle.h" | 21 #include "mojo/public/cpp/system/handle.h" |
21 | 22 |
22 namespace media { | 23 namespace media { |
23 | 24 |
24 MojoVideoDecoderService::MojoVideoDecoderService( | 25 MojoVideoDecoderService::MojoVideoDecoderService( |
25 MojoMediaClient* mojo_media_client) | 26 MojoMediaClient* mojo_media_client) |
26 : mojo_media_client_(mojo_media_client), weak_factory_(this) { | 27 : mojo_media_client_(mojo_media_client), weak_factory_(this) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 | 67 |
67 void MojoVideoDecoderService::OnDecoderInitialized( | 68 void MojoVideoDecoderService::OnDecoderInitialized( |
68 const InitializeCallback& callback, | 69 const InitializeCallback& callback, |
69 bool success) { | 70 bool success) { |
70 DVLOG(1) << __FUNCTION__; | 71 DVLOG(1) << __FUNCTION__; |
71 callback.Run(success); | 72 callback.Run(success); |
72 } | 73 } |
73 | 74 |
74 void MojoVideoDecoderService::OnDecoderOutput( | 75 void MojoVideoDecoderService::OnDecoderOutput( |
75 const scoped_refptr<VideoFrame>& frame) { | 76 const scoped_refptr<VideoFrame>& frame) { |
76 DVLOG(1) << __FUNCTION__; | 77 VLOG(0) << __FUNCTION__; |
77 DCHECK(client_); | 78 DCHECK(client_); |
78 client_->OnVideoFrameDecoded(mojom::VideoFrame::From(frame)); | 79 |
| 80 const size_t y_plane_size = |
| 81 frame->rows(VideoFrame::kYPlane) * frame->stride(VideoFrame::kYPlane); |
| 82 const size_t u_plane_size = |
| 83 frame->rows(VideoFrame::kUPlane) * frame->stride(VideoFrame::kUPlane); |
| 84 |
| 85 // Allocate a mojo::SharedBufferHandle big enough to contain |frame|'s data. |
| 86 size_t buffer_size = |
| 87 VideoFrame::AllocationSize(frame->format(), frame->coded_size()); |
| 88 mojo::ScopedSharedBufferHandle shared_buffer = |
| 89 mojo::SharedBufferHandle::Create(buffer_size); |
| 90 DCHECK(shared_buffer.is_valid()); |
| 91 mojo::ScopedSharedBufferMapping shared_buffer_memory = |
| 92 shared_buffer->Map(buffer_size); |
| 93 |
| 94 // Copy data into the shared buffer. |
| 95 size_t offset = 0; |
| 96 static size_t planes[] = {VideoFrame::kYPlane, VideoFrame::kUPlane, |
| 97 VideoFrame::kVPlane}; |
| 98 for (size_t plane : planes) { |
| 99 size_t plane_size = frame->rows(plane) * frame->stride(plane); |
| 100 memcpy(reinterpret_cast<uint8_t*>(shared_buffer_memory.get()) + offset, |
| 101 frame->data(plane), plane_size); |
| 102 offset += plane_size; |
| 103 } |
| 104 |
| 105 // Create a MojoSharedBufferVideoFrame whose dimensions match |color_frame|. |
| 106 scoped_refptr<VideoFrame> mojo_frame = MojoSharedBufferVideoFrame::Create( |
| 107 frame->format(), frame->coded_size(), frame->visible_rect(), |
| 108 frame->natural_size(), std::move(shared_buffer), buffer_size, 0, |
| 109 y_plane_size, y_plane_size + u_plane_size, |
| 110 frame->stride(VideoFrame::kYPlane), frame->stride(VideoFrame::kUPlane), |
| 111 frame->stride(VideoFrame::kVPlane), frame->timestamp()); |
| 112 |
| 113 client_->OnVideoFrameDecoded(mojom::VideoFrame::From(mojo_frame)); |
79 } | 114 } |
80 | 115 |
81 void MojoVideoDecoderService::Decode(mojom::DecoderBufferPtr buffer, | 116 void MojoVideoDecoderService::Decode(mojom::DecoderBufferPtr buffer, |
82 const DecodeCallback& callback) { | 117 const DecodeCallback& callback) { |
83 DVLOG(1) << __FUNCTION__; | 118 DVLOG(1) << __FUNCTION__; |
84 | 119 |
85 if (!decoder_) { | 120 if (!decoder_) { |
86 callback.Run(mojom::DecodeStatus::DECODE_ERROR); | 121 callback.Run(mojom::DecodeStatus::DECODE_ERROR); |
87 return; | 122 return; |
88 } | 123 } |
(...skipping 29 matching lines...) Expand all Loading... |
118 decoder_->Reset(base::Bind(&MojoVideoDecoderService::OnDecoderReset, | 153 decoder_->Reset(base::Bind(&MojoVideoDecoderService::OnDecoderReset, |
119 weak_this_, callback)); | 154 weak_this_, callback)); |
120 } | 155 } |
121 | 156 |
122 void MojoVideoDecoderService::OnDecoderReset(const ResetCallback& callback) { | 157 void MojoVideoDecoderService::OnDecoderReset(const ResetCallback& callback) { |
123 DVLOG(1) << __FUNCTION__; | 158 DVLOG(1) << __FUNCTION__; |
124 callback.Run(); | 159 callback.Run(); |
125 } | 160 } |
126 | 161 |
127 } // namespace media | 162 } // namespace media |
OLD | NEW |