Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
|
wuchengli
2015/05/04 14:14:41
I know the current patchset has a bug and the perf
kcwu
2015/05/08 14:42:42
Done.
| |
| 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 CONTENT_BROWSER_RENDERER_HOST_GPU_JPEG_DECODER_H_ | |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_GPU_JPEG_DECODER_H_ | |
| 7 | |
| 8 #include "base/callback.h" | |
| 9 #include "base/memory/ref_counted.h" | |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "content/common/content_export.h" | |
| 12 #include "media/video/capture/video_capture_device.h" | |
| 13 #include "media/video/jpeg_decode_accelerator.h" | |
| 14 | |
| 15 namespace base { | |
| 16 class MessageLoopProxy; | |
| 17 } | |
| 18 | |
| 19 namespace media { | |
| 20 class VideoFrame; | |
| 21 } | |
| 22 | |
| 23 namespace content { | |
| 24 | |
| 25 // Adapter to GpuJpegDecodeAccelerator for VideoCaptureDevice::Client. It takes | |
| 26 // care of GpuJpegDecodeAccelerator creation, shared memory, and threading | |
| 27 // issues. If decoding fails, it will fallback to software decode for current | |
| 28 // frame and reject upcoming frames. | |
| 29 // | |
| 30 // There are two threads involved in this class. The constructor, | |
| 31 // destructor, and the decoding responses (JpegDecodeAccelerator::Client | |
| 32 // functions) run on IO thread. Initialize() and DecodeCapturedData() run on | |
| 33 // the other thread (i.e., device thread for Linux). | |
| 34 class CONTENT_EXPORT GpuJpegDecoder | |
| 35 : public media::JpegDecodeAccelerator::Client { | |
| 36 public: | |
| 37 typedef base::Callback<void( | |
| 38 scoped_ptr<media::VideoCaptureDevice::Client::Buffer>, | |
| 39 const scoped_refptr<media::VideoFrame>&, | |
| 40 const base::TimeTicks&)> DecodeDoneCB; | |
| 41 | |
| 42 // Returns true if JPEG hardware decoding is supported on this device. | |
| 43 static bool Supported(); | |
| 44 | |
| 45 // |device_client| is where we request VideoCaptureDevice::Client::Buffer as | |
| 46 // output buffer from and send decoded result to. | |
| 47 GpuJpegDecoder(media::VideoCaptureDevice::Client* device_client, | |
| 48 const DecodeDoneCB& decode_done_cb); | |
|
wuchengli
2015/05/04 14:14:41
Can GpuJpegDecoder call device_client_->OnIncoming
kcwu
2015/05/08 14:42:42
I found ReserveOutputBuffer can be done outside of
| |
| 49 ~GpuJpegDecoder(); | |
| 50 | |
| 51 // Creates and intializes decoder in GPU side. Do nothing if already | |
|
wuchengli
2015/05/04 14:14:41
"Do nothing if already initialized" is strange. Th
kcwu
2015/05/08 14:42:42
Done.
| |
| 52 // initialized. Return falses if failed. | |
|
wuchengli
2015/05/04 14:14:41
s/Return falses/Returns false/
kcwu
2015/05/08 14:42:42
Done.
| |
| 53 bool Initialize(); | |
| 54 | |
| 55 // Decodes a JPEG picture. Returns true iff GpuJpegDecoder is not in failed | |
| 56 // state and accepts this decode request. | |
| 57 bool DecodeCapturedData(const uint8* data, | |
| 58 size_t in_buffer_size, | |
| 59 const media::VideoCaptureFormat& frame_format, | |
| 60 int rotation, | |
| 61 const base::TimeTicks& timestamp); | |
| 62 | |
| 63 // JpegDecodeAccelerator::Client implementation. | |
| 64 // These will be called on IO thread. | |
| 65 virtual void VideoFrameReady(int32_t buffer_id) override; | |
| 66 virtual void NotifyError(int32_t buffer_id, | |
| 67 media::JpegDecodeAccelerator::Error error) override; | |
| 68 | |
| 69 private: | |
| 70 // Returns true if the decoding of last frame is not finished yet. | |
| 71 bool IsDecoding_Locked(); | |
| 72 | |
| 73 // The "customer" of GpuJpegDecoder. | |
| 74 media::VideoCaptureDevice::Client* device_client_; | |
| 75 | |
| 76 // The callback when decode succeed. | |
| 77 DecodeDoneCB decode_done_cb_; | |
| 78 | |
| 79 // The capture thread. | |
|
wuchengli
2015/05/04 14:14:41
Add documentation what a capture thread is. Withou
kcwu
2015/05/08 14:42:42
Done.
| |
| 80 const scoped_refptr<base::MessageLoopProxy> capture_task_runner_; | |
| 81 | |
| 82 // The underlying JPEG decode accelerator. | |
| 83 scoped_ptr<media::JpegDecodeAccelerator> decoder_; | |
| 84 | |
| 85 // Guards |failed_|, |decode_done_closure_|, and |in_buffer_|. | |
| 86 base::Lock lock_; | |
| 87 | |
| 88 bool initialized_; | |
| 89 bool failed_; | |
|
wuchengli
2015/05/04 14:14:41
Add a status callback so you don't need |failed_|.
wuchengli
2015/05/06 07:59:18
See the comment in DecodeCapturedData. If we retur
kcwu
2015/05/08 14:42:42
Done.
kcwu
2015/05/08 14:42:42
Acknowledged.
| |
| 90 | |
| 91 // The closure of |decode_done_cb_| with bound parameters. | |
| 92 base::Closure decode_done_closure_; | |
| 93 | |
| 94 // Next id for |in_buffer_|. | |
| 95 int32 next_bitstream_buffer_id_; | |
| 96 | |
| 97 // Shared memory to store JPEG stream buffer. |in_buffer_| is backed by this. | |
| 98 scoped_ptr<base::SharedMemory> in_shared_memory_; | |
| 99 | |
| 100 // JPEG stream buffer as input to JpegDecodeAccelerator. | |
| 101 media::BitstreamBuffer in_buffer_; | |
| 102 | |
| 103 DISALLOW_COPY_AND_ASSIGN(GpuJpegDecoder); | |
| 104 }; | |
| 105 | |
| 106 } // namespace content | |
| 107 | |
| 108 #endif // CONTENT_BROWSER_RENDERER_HOST_GPU_JPEG_DECODER_H_ | |
| OLD | NEW |