Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 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 #include "content/common/gpu/media/gpu_video_encode_accelerator.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "content/common/gpu/gpu_channel.h" | |
| 9 #include "content/common/gpu/gpu_messages.h" | |
| 10 #include "ipc/ipc_message_macros.h" | |
| 11 | |
| 12 namespace content { | |
| 13 | |
| 14 GpuVideoEncodeAccelerator::GpuVideoEncodeAccelerator(GpuChannel* gpu_channel, | |
| 15 int32 route_id) | |
| 16 : channel_(gpu_channel), route_id_(route_id) {} | |
| 17 | |
| 18 GpuVideoEncodeAccelerator::~GpuVideoEncodeAccelerator() { | |
| 19 encoder_.release()->Destroy(); | |
|
Ami GONE FROM CHROMIUM
2013/07/31 23:01:12
will crash if CreateEncoder() didn't succeed.
sheu
2013/08/02 01:27:49
Done.
| |
| 20 } | |
| 21 | |
| 22 bool GpuVideoEncodeAccelerator::OnMessageReceived(const IPC::Message& message) { | |
| 23 bool handled = true; | |
| 24 IPC_BEGIN_MESSAGE_MAP(GpuVideoEncodeAccelerator, message) | |
| 25 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderMsg_Initialize, OnInitialize) | |
| 26 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderMsg_Encode, OnEncode) | |
| 27 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderMsg_UseOutputBitstreamBuffer, | |
| 28 OnUseOutputBitstreamBuffer) | |
| 29 IPC_MESSAGE_HANDLER( | |
| 30 AcceleratedVideoEncoderMsg_RequestEncodingParameterChange, | |
| 31 OnRequestEncodingParameterChange) | |
| 32 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 33 IPC_END_MESSAGE_MAP() | |
| 34 return handled; | |
| 35 } | |
| 36 | |
| 37 void GpuVideoEncodeAccelerator::OnChannelError() { | |
| 38 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError); | |
| 39 if (channel_) | |
| 40 channel_ = NULL; | |
| 41 } | |
| 42 | |
| 43 void GpuVideoEncodeAccelerator::NotifyInitializeDone() { | |
| 44 if (!Send( | |
| 45 new AcceleratedVideoEncoderHostMsg_NotifyInitializeDone(route_id_))) { | |
| 46 DLOG(ERROR) << "GpuVideoEncodeAccelerator::NotifyInitializeDone(): " | |
|
Ami GONE FROM CHROMIUM
2013/07/31 23:01:12
Here and (lots of) elsewhere, Send() does its own
sheu
2013/08/02 01:27:49
Sounds good.
| |
| 47 "Send() failed"; | |
| 48 } | |
| 49 } | |
| 50 | |
| 51 void GpuVideoEncodeAccelerator::RequireBitstreamBuffers( | |
| 52 int input_count, | |
| 53 const gfx::Size& input_dimensions, | |
| 54 size_t output_size) { | |
| 55 if (!Send(new AcceleratedVideoEncoderHostMsg_RequireBitstreamBuffers( | |
| 56 route_id_, input_count, input_dimensions, output_size))) { | |
| 57 DLOG(ERROR) << "GpuVideoEncodeAccelerator::RequireBitstreamBuffers(): " | |
| 58 "Send() failed"; | |
| 59 } | |
| 60 } | |
| 61 | |
| 62 void GpuVideoEncodeAccelerator::NotifyInputDone(int32 bitstream_buffer_id) { | |
| 63 if (!Send(new AcceleratedVideoEncoderHostMsg_NotifyInputDone( | |
| 64 route_id_, bitstream_buffer_id))) { | |
| 65 DLOG(ERROR) << "GpuVideoEncodeAccelerator::NotifyInputDone(): " | |
| 66 "Send() failed: bitstream_buffer_id=" << bitstream_buffer_id; | |
| 67 } | |
| 68 } | |
| 69 | |
| 70 void GpuVideoEncodeAccelerator::BitstreamBufferReady(int32 bitstream_buffer_id, | |
| 71 size_t payload_size, | |
| 72 bool key_frame) { | |
| 73 if (!Send(new AcceleratedVideoEncoderHostMsg_BitstreamBufferReady( | |
| 74 route_id_, bitstream_buffer_id, payload_size, key_frame))) { | |
| 75 DLOG(ERROR) << "GpuVideoEncodeAccelerator::BitstreamBufferReady(): " | |
| 76 "Send() failed: bitstream_buffer_id=" << bitstream_buffer_id; | |
| 77 } | |
| 78 } | |
| 79 | |
| 80 void GpuVideoEncodeAccelerator::NotifyError( | |
| 81 media::VideoEncodeAccelerator::Error error) { | |
| 82 if (!Send(new AcceleratedVideoEncoderHostMsg_NotifyError(route_id_, error))) { | |
| 83 DLOG(ERROR) << "GpuVideoEncodeAccelerator::NotifyError(): Send() failed: " | |
| 84 "error=" << error; | |
| 85 } | |
| 86 } | |
| 87 | |
| 88 // static | |
| 89 std::vector<media::VideoEncodeAccelerator::SupportedProfile> | |
| 90 GpuVideoEncodeAccelerator::GetSupportedProfiles() { | |
| 91 std::vector<media::VideoEncodeAccelerator::SupportedProfile> profiles; | |
| 92 | |
| 93 // TODO(sheu): return platform-specific profiles. | |
| 94 return profiles; | |
| 95 } | |
| 96 | |
| 97 scoped_ptr<media::VideoEncodeAccelerator> | |
| 98 GpuVideoEncodeAccelerator::CreateEncoder() { | |
| 99 scoped_ptr<media::VideoEncodeAccelerator> encoder; | |
| 100 | |
| 101 // TODO(sheu): return platform-specific encoder. | |
| 102 return encoder.Pass(); | |
| 103 } | |
| 104 | |
| 105 bool GpuVideoEncodeAccelerator::Send(IPC::Message* message) { | |
| 106 if (!channel_) { | |
| 107 DLOG(ERROR) << "GpuVideoEncodeAccelerator::Send(): no channel"; | |
| 108 delete message; | |
|
Ami GONE FROM CHROMIUM
2013/07/31 23:01:12
NotifyError?
sheu
2013/08/02 01:27:49
<zen> what is the sound of a NULL IPC channel send
| |
| 109 return false; | |
| 110 } else if (!channel_->Send(message)) { | |
| 111 DLOG(ERROR) << "GpuVideoEncodeAccelerator::Send(): sending failed"; | |
| 112 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError); | |
| 113 return false; | |
| 114 } | |
| 115 return true; | |
| 116 } | |
| 117 | |
| 118 void GpuVideoEncodeAccelerator::OnInitialize( | |
| 119 media::VideoFrame::Format input_format, | |
| 120 const gfx::Size& input_resolution, | |
| 121 media::VideoCodecProfile output_profile, | |
| 122 int32 initial_bitrate) { | |
| 123 DVLOG(2) << "GpuVideoEncodeAccelerator::OnInitialize(): " | |
| 124 "input_format=" << input_format | |
| 125 << ", input_resolution=" << input_resolution.width() | |
| 126 << "x" << input_resolution.height() | |
|
Ami GONE FROM CHROMIUM
2013/07/31 23:01:12
here and elsewhere you could use gfx::Size::ToStri
sheu
2013/08/02 01:27:49
Did not know that existed. Sweet!
| |
| 127 << ", output_profile=" << output_profile | |
| 128 << ", initial_bitrate=" << initial_bitrate; | |
| 129 DCHECK(!encoder_); | |
| 130 encoder_ = CreateEncoder().Pass(); | |
| 131 if (!encoder_) { | |
| 132 DLOG(ERROR) << "GpuVideoEncodeAccelerator::OnInitialize(): VEA creation " | |
| 133 "failed"; | |
| 134 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError); | |
| 135 return; | |
| 136 } | |
| 137 | |
| 138 encoder_->Initialize( | |
| 139 input_format, input_resolution, output_profile, initial_bitrate); | |
| 140 } | |
| 141 | |
| 142 void GpuVideoEncodeAccelerator::OnEncode(int32 buffer_id, | |
| 143 base::SharedMemoryHandle buffer_handle, | |
| 144 uint32 buffer_size, | |
| 145 bool force_keyframe) { | |
| 146 DVLOG(3) << "GpuVideoEncodeAccelerator::OnEncode(): buffer_id=" << buffer_id | |
| 147 << ", buffer_size=" << buffer_size | |
| 148 << ", force_keyframe=" << force_keyframe; | |
| 149 if (!encoder_) | |
| 150 return; | |
| 151 if (buffer_id < 0) { | |
| 152 DLOG(ERROR) << "GpuVideoEncodeAccelerator::OnEncode(): invalid buffer_id=" | |
| 153 << buffer_id; | |
| 154 NotifyError(media::VideoEncodeAccelerator::kInvalidArgumentError); | |
| 155 return; | |
| 156 } | |
| 157 encoder_->Encode( | |
| 158 media::BitstreamBuffer(buffer_id, buffer_handle, buffer_size), | |
| 159 force_keyframe); | |
| 160 } | |
| 161 | |
| 162 void GpuVideoEncodeAccelerator::OnUseOutputBitstreamBuffer( | |
| 163 int32 buffer_id, | |
| 164 base::SharedMemoryHandle buffer_handle, | |
| 165 uint32 buffer_size) { | |
| 166 DVLOG(3) << "GpuVideoEncodeAccelerator::OnUseOutputBitstreamBuffer(): " | |
| 167 "buffer_id=" << buffer_id | |
| 168 << ", buffer_size=" << buffer_size; | |
| 169 if (!encoder_) | |
| 170 return; | |
| 171 if (buffer_id < 0) { | |
| 172 DLOG(ERROR) << "GpuVideoEncodeAccelerator::OnEncode(): invalid buffer_id=" | |
| 173 << buffer_id; | |
| 174 NotifyError(media::VideoEncodeAccelerator::kInvalidArgumentError); | |
| 175 return; | |
| 176 } | |
| 177 encoder_->UseOutputBitstreamBuffer( | |
| 178 media::BitstreamBuffer(buffer_id, buffer_handle, buffer_size)); | |
| 179 } | |
| 180 | |
| 181 void GpuVideoEncodeAccelerator::OnRequestEncodingParameterChange( | |
| 182 int32 bitrate) { | |
| 183 DVLOG(2) << "GpuVideoEncodeAccelerator::OnRequestEncodingParametersChange(): " | |
| 184 "bitrate=" << bitrate; | |
| 185 if (!encoder_) | |
| 186 return; | |
| 187 encoder_->RequestEncodingParameterChange(bitrate); | |
| 188 } | |
| 189 | |
| 190 } // namespace content | |
| OLD | NEW |