1 // Copyright 2015 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 // Note: ported from Chromium commit head: 77118c9 5 6 #ifndef ACCELERATED_VIDEO_DECODER_H_ 7 #define ACCELERATED_VIDEO_DECODER_H_ 8 9 #include <stddef.h> 10 #include <stdint.h> 11 12 #include "base/macros.h" 13 #include "size.h" 14 15 namespace media { 16 17 // An AcceleratedVideoDecoder is a video decoder that requires support from an 18 // external accelerator (typically a hardware accelerator) to partially offload 19 // the decode process after parsing stream headers, and performing reference 20 // frame and state management. 21 class AcceleratedVideoDecoder { 22 public: AcceleratedVideoDecoder()23 AcceleratedVideoDecoder() {} ~AcceleratedVideoDecoder()24 virtual ~AcceleratedVideoDecoder() {} 25 26 virtual void SetStream(const uint8_t* ptr, size_t size) = 0; 27 28 // Have the decoder flush its state and trigger output of all previously 29 // decoded surfaces. Return false on failure. 30 virtual bool Flush() WARN_UNUSED_RESULT = 0; 31 32 // Stop (pause) decoding, discarding all remaining inputs and outputs, 33 // but do not flush decoder state, so that playback can be resumed later, 34 // possibly from a different location. 35 // To be called during decoding. 36 virtual void Reset() = 0; 37 38 enum DecodeResult { 39 kDecodeError, // Error while decoding. 40 // TODO(posciak): unsupported streams are currently treated as error 41 // in decoding; in future it could perhaps be possible to fall back 42 // to software decoding instead. 43 // kStreamError, // Error in stream. 44 kAllocateNewSurfaces, // Need a new set of surfaces to be allocated. 45 kRanOutOfStreamData, // Need more stream data to proceed. 46 kRanOutOfSurfaces, // Waiting for the client to free up output surfaces. 47 kNeedContextUpdate, // Waiting for the client to update decoding context 48 // with data acquired from the accelerator. 49 }; 50 51 // Try to decode more of the stream, returning decoded frames asynchronously. 52 // Return when more stream is needed, when we run out of free surfaces, when 53 // we need a new set of them, or when an error occurs. 54 virtual DecodeResult Decode() WARN_UNUSED_RESULT = 0; 55 56 // Return dimensions/required number of output surfaces that client should 57 // be ready to provide for the decoder to function properly. 58 // To be used after Decode() returns kAllocateNewSurfaces. 59 virtual Size GetPicSize() const = 0; 60 virtual size_t GetRequiredNumOfPictures() const = 0; 61 62 private: 63 DISALLOW_COPY_AND_ASSIGN(AcceleratedVideoDecoder); 64 }; 65 66 } // namespace media 67 68 #endif // ACCELERATED_VIDEO_DECODER_H_ 69