OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. |
| 4 // |
| 5 // Decodes H.264 Annex B streams using the Media Foundation H.264 decoder as |
| 6 // a standalone Media Foundation Transform (MFT). |
| 7 // Note: A single MftH264Decoder instance is only for 1 H.264 video stream only. |
| 8 // Inputting streams consisting of more than 1 video to a single instance |
| 9 // may result in undefined behavior. |
| 10 |
| 11 #ifndef MEDIA_MF_MFT_H264_DECODER_H_ |
| 12 #define MEDIA_MF_MFT_H264_DECODER_H_ |
| 13 |
| 14 #include <string> |
| 15 |
| 16 #include <mfidl.h> |
| 17 |
| 18 #include "base/basictypes.h" |
| 19 #include "base/callback.h" |
| 20 #include "base/scoped_ptr.h" |
| 21 #include "base/scoped_comptr_win.h" |
| 22 |
| 23 struct IDirect3DDeviceManager9; |
| 24 struct IMFSample; |
| 25 struct IMFTransform; |
| 26 |
| 27 namespace media { |
| 28 |
| 29 class VideoFrame; |
| 30 |
| 31 // A decoder that takes samples of Annex B streams then outputs decoded frames. |
| 32 class MftH264Decoder { |
| 33 public: |
| 34 typedef Callback4<uint8**, int*, int64*, int64*>::Type ReadInputCallback; |
| 35 typedef Callback1<scoped_refptr<VideoFrame> >::Type OutputReadyCallback; |
| 36 enum DecoderOutputState { |
| 37 kOutputOk = 0, |
| 38 kResetOutputStreamFailed, |
| 39 kNoMoreOutput, |
| 40 kUnspecifiedError, |
| 41 kNoMemory, |
| 42 kOutputSampleError |
| 43 }; |
| 44 explicit MftH264Decoder(bool use_dxva); |
| 45 ~MftH264Decoder(); |
| 46 |
| 47 // Initializes the decoder. |dev_manager| is not required if the decoder does |
| 48 // not use DXVA. |
| 49 // If the other arguments are not known, leave them as 0. They can be |
| 50 // provided to the decoder to try to avoid an initial output format change, |
| 51 // but it is not necessary to have them. |
| 52 // The object takes ownership of the callbacks. However, the caller must |
| 53 // make sure the objects associated with the callbacks outlives the time |
| 54 // when GetOutput() will be called. |
| 55 bool Init(IDirect3DDeviceManager9* dev_manager, |
| 56 int frame_rate_num, int frame_rate_denom, |
| 57 int width, int height, |
| 58 int aspect_num, int aspect_denom, |
| 59 ReadInputCallback* read_input_cb, |
| 60 OutputReadyCallback* output_avail_cb); |
| 61 |
| 62 // Sends an Annex B stream to the decoder. The times here should be given |
| 63 // in 100ns units. This creates a IMFSample, copies the stream over to the |
| 64 // sample, and sends the sample to the decoder. |
| 65 // Returns: true if the sample was sent successfully. |
| 66 bool SendInput(uint8* data, int size, int64 timestamp, int64 duration); |
| 67 |
| 68 // Tries to get an output sample from the decoder, and if successful, calls |
| 69 // the callback with the sample. |
| 70 // Returns: status of the decoder. |
| 71 DecoderOutputState GetOutput(); |
| 72 |
| 73 bool initialized() const { return initialized_; } |
| 74 bool use_dxva() const { return use_dxva_; } |
| 75 bool drain_message_sent() const { return drain_message_sent_; } |
| 76 int in_buffer_size() const { return in_buffer_size_; } |
| 77 int out_buffer_size() const { return out_buffer_size_; } |
| 78 int frames_read() const { return frames_read_; } |
| 79 int frames_decoded() const { return frames_decoded_; } |
| 80 int width() const { return width_; } |
| 81 int height() const { return height_; } |
| 82 |
| 83 private: |
| 84 bool InitDecoder(IDirect3DDeviceManager9* dev_manager, |
| 85 int frame_rate_num, int frame_rate_denom, |
| 86 int width, int height, |
| 87 int aspect_num, int aspect_denom); |
| 88 bool CheckDecoderProperties(); |
| 89 bool CheckDecoderDxvaSupport(); |
| 90 bool SetDecoderD3d9Manager(IDirect3DDeviceManager9* dev_manager); |
| 91 bool SetDecoderMediaTypes(int frame_rate_num, int frame_rate_denom, |
| 92 int width, int height, |
| 93 int aspect_num, int aspect_denom); |
| 94 bool SetDecoderInputMediaType(int frame_rate_num, int frame_rate_denom, |
| 95 int width, int height, |
| 96 int aspect_num, int aspect_denom); |
| 97 bool SetDecoderOutputMediaType(const GUID subtype); |
| 98 bool SendStartMessage(); |
| 99 bool GetStreamsInfoAndBufferReqs(); |
| 100 bool ReadAndProcessInput(); |
| 101 |
| 102 // Sends a drain message to the decoder to indicate no more input will be |
| 103 // sent. SendInput() should not be called after calling this method. |
| 104 // Returns: true if the drain message was sent successfully. |
| 105 bool SendDrainMessage(); |
| 106 |
| 107 scoped_ptr<ReadInputCallback> read_input_callback_; |
| 108 scoped_ptr<OutputReadyCallback> output_avail_callback_; |
| 109 ScopedComPtr<IMFTransform> decoder_; |
| 110 bool initialized_; |
| 111 bool use_dxva_; |
| 112 bool drain_message_sent_; |
| 113 |
| 114 // Minimum input and output buffer sizes as required by the decoder. |
| 115 int32 in_buffer_size_; |
| 116 int32 out_buffer_size_; |
| 117 int32 frames_read_; |
| 118 int32 frames_decoded_; |
| 119 int32 width_; |
| 120 int32 height_; |
| 121 int32 stride_; |
| 122 |
| 123 DISALLOW_COPY_AND_ASSIGN(MftH264Decoder); |
| 124 }; |
| 125 |
| 126 } // namespace media |
| 127 |
| 128 #endif // MEDIA_MF_MFT_H264_DECODER_H_ |
OLD | NEW |