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