| 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 #ifndef EXTENSIONS_RENDERER_API_DISPLAY_SOURCE_WIFI_DISPLAY_WIFI_DISPLAY_VIDEO_E
NCODER_H_ | 5 #ifndef EXTENSIONS_RENDERER_API_DISPLAY_SOURCE_WIFI_DISPLAY_WIFI_DISPLAY_VIDEO_E
NCODER_H_ |
| 6 #define EXTENSIONS_RENDERER_API_DISPLAY_SOURCE_WIFI_DISPLAY_WIFI_DISPLAY_VIDEO_E
NCODER_H_ | 6 #define EXTENSIONS_RENDERER_API_DISPLAY_SOURCE_WIFI_DISPLAY_WIFI_DISPLAY_VIDEO_E
NCODER_H_ |
| 7 | 7 |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/memory/shared_memory.h" | 8 #include "base/memory/shared_memory.h" |
| 11 #include "base/stl_util.h" | 9 #include "extensions/renderer/api/display_source/wifi_display/wifi_display_media
_encoder.h" |
| 12 #include "media/base/video_frame.h" | 10 #include "media/base/video_frame.h" |
| 13 #include "media/video/video_encode_accelerator.h" | 11 #include "media/video/video_encode_accelerator.h" |
| 14 #include "third_party/wds/src/libwds/public/video_format.h" | 12 #include "third_party/wds/src/libwds/public/video_format.h" |
| 15 | 13 |
| 16 namespace extensions { | 14 namespace extensions { |
| 17 | 15 |
| 18 // This structure represents an encoded video frame. | 16 using WiFiDisplayEncodedFrame = WiFiDisplayEncodedUnit; |
| 19 struct WiFiDisplayEncodedFrame { | |
| 20 const uint8_t* bytes() const { | |
| 21 return reinterpret_cast<uint8_t*>( | |
| 22 string_as_array(const_cast<std::string*>(&data))); | |
| 23 } | |
| 24 uint8_t* mutable_bytes() { | |
| 25 return reinterpret_cast<uint8_t*>(string_as_array(&data)); | |
| 26 } | |
| 27 | |
| 28 base::TimeTicks pts; // Presentation timestamp. | |
| 29 base::TimeTicks dts; // Decoder timestamp. | |
| 30 std::string data; | |
| 31 bool key_frame; | |
| 32 }; | |
| 33 | 17 |
| 34 // This interface represents H.264 video encoder used by the | 18 // This interface represents H.264 video encoder used by the |
| 35 // Wi-Fi Display media pipeline. | 19 // Wi-Fi Display media pipeline. |
| 36 // Threading: the client code should belong to a single thread. | 20 // Threading: the client code should belong to a single thread. |
| 37 class WiFiDisplayVideoEncoder : | 21 class WiFiDisplayVideoEncoder : public WiFiDisplayMediaEncoder { |
| 38 public base::RefCountedThreadSafe<WiFiDisplayVideoEncoder> { | |
| 39 public: | 22 public: |
| 40 using EncodedFrameCallback = | |
| 41 base::Callback<void(const WiFiDisplayEncodedFrame&)>; | |
| 42 | |
| 43 using VideoEncoderCallback = | 23 using VideoEncoderCallback = |
| 44 base::Callback<void(scoped_refptr<WiFiDisplayVideoEncoder>)>; | 24 base::Callback<void(scoped_refptr<WiFiDisplayVideoEncoder>)>; |
| 45 | 25 |
| 46 using ReceiveVideoEncodeAcceleratorCallback = | 26 using ReceiveVideoEncodeAcceleratorCallback = |
| 47 base::Callback<void(scoped_refptr<base::SingleThreadTaskRunner>, | 27 base::Callback<void(scoped_refptr<base::SingleThreadTaskRunner>, |
| 48 std::unique_ptr<media::VideoEncodeAccelerator>)>; | 28 std::unique_ptr<media::VideoEncodeAccelerator>)>; |
| 49 using CreateVideoEncodeAcceleratorCallback = | 29 using CreateVideoEncodeAcceleratorCallback = |
| 50 base::Callback<void(const ReceiveVideoEncodeAcceleratorCallback&)>; | 30 base::Callback<void(const ReceiveVideoEncodeAcceleratorCallback&)>; |
| 51 | 31 |
| 52 using ReceiveEncodeMemoryCallback = | 32 using ReceiveEncodeMemoryCallback = |
| 53 base::Callback<void(std::unique_ptr<base::SharedMemory>)>; | 33 base::Callback<void(std::unique_ptr<base::SharedMemory>)>; |
| 54 using CreateEncodeMemoryCallback = | 34 using CreateEncodeMemoryCallback = |
| 55 base::Callback<void(size_t size, const ReceiveEncodeMemoryCallback&)>; | 35 base::Callback<void(size_t size, const ReceiveEncodeMemoryCallback&)>; |
| 56 | 36 |
| 57 struct InitParameters { | 37 struct InitParameters { |
| 58 InitParameters(); | 38 InitParameters(); |
| 59 InitParameters(const InitParameters&); | 39 InitParameters(const InitParameters&); |
| 60 ~InitParameters(); | 40 ~InitParameters(); |
| 61 gfx::Size frame_size; | 41 gfx::Size frame_size; |
| 62 int frame_rate; | 42 int frame_rate; |
| 63 int bit_rate; | 43 int bit_rate; |
| 64 wds::H264Profile profile; | 44 wds::H264Profile profile; |
| 65 wds::H264Level level; | 45 wds::H264Level level; |
| 66 // VEA-specific parameters. | 46 // VEA-specific parameters. |
| 67 CreateEncodeMemoryCallback create_memory_callback; | 47 CreateEncodeMemoryCallback create_memory_callback; |
| 68 CreateVideoEncodeAcceleratorCallback vea_create_callback; | 48 CreateVideoEncodeAcceleratorCallback vea_create_callback; |
| 69 }; | 49 }; |
| 70 | 50 |
| 71 // A factory method that creates a new encoder instance from the given | 51 // A factory method that creates a new encoder instance from the given |
| 72 // |params|, the encoder instance is returned as an argument of | 52 // |params|, the encoder instance is returned as an argument of |
| 73 // |result_callback| ('nullptr' argument means encoder creation failure). | 53 // |result_callback| ('nullptr' argument means encoder creation failure). |
| 74 static void Create( | 54 static void Create(const InitParameters& params, |
| 75 const InitParameters& params, | 55 const VideoEncoderCallback& encoder_callback); |
| 76 const VideoEncoderCallback& encoder_callback); | |
| 77 | 56 |
| 78 // Encodes the given raw frame. The resulting encoded frame is passed | 57 // Encodes the given raw frame. The resulting encoded frame is passed |
| 79 // as an |encoded_callback|'s argument which is set via 'SetCallbacks' | 58 // as an |encoded_callback|'s argument which is set via 'SetCallbacks' |
| 80 // method. | 59 // method. |
| 81 virtual void InsertRawVideoFrame( | 60 virtual void InsertRawVideoFrame( |
| 82 const scoped_refptr<media::VideoFrame>& video_frame, | 61 const scoped_refptr<media::VideoFrame>& video_frame, |
| 83 base::TimeTicks reference_time) = 0; | 62 base::TimeTicks reference_time) = 0; |
| 84 | 63 |
| 85 // Requests the next encoded frame to be an instantaneous decoding refresh | 64 // Requests the next encoded frame to be an instantaneous decoding refresh |
| 86 // (IDR) picture. | 65 // (IDR) picture. |
| 87 virtual void RequestIDRPicture() = 0; | 66 virtual void RequestIDRPicture() = 0; |
| 88 | 67 |
| 89 // Sets callbacks for the obtained encoder instance: | |
| 90 // |encoded_callback| is invoked to return the next encoded frame | |
| 91 // |error_callback| is invoked to report a fatal encoder error | |
| 92 void SetCallbacks(const EncodedFrameCallback& encoded_callback, | |
| 93 const base::Closure& error_callback); | |
| 94 | |
| 95 protected: | 68 protected: |
| 96 friend class base::RefCountedThreadSafe<WiFiDisplayVideoEncoder>; | |
| 97 WiFiDisplayVideoEncoder(); | 69 WiFiDisplayVideoEncoder(); |
| 98 virtual ~WiFiDisplayVideoEncoder(); | 70 ~WiFiDisplayVideoEncoder() override; |
| 99 | |
| 100 EncodedFrameCallback encoded_callback_; | |
| 101 base::Closure error_callback_; | |
| 102 }; | 71 }; |
| 103 | 72 |
| 104 } // namespace extensions | 73 } // namespace extensions |
| 105 | 74 |
| 106 #endif // EXTENSIONS_RENDERER_API_DISPLAY_SOURCE_WIFI_DISPLAY_WIFI_DISPLAY_VIDE
O_ENCODER_H_ | 75 #endif // EXTENSIONS_RENDERER_API_DISPLAY_SOURCE_WIFI_DISPLAY_WIFI_DISPLAY_VIDE
O_ENCODER_H_ |
| OLD | NEW |