1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68

media / gpu / test / bitstream_helpers.h [blame]

// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MEDIA_GPU_TEST_BITSTREAM_HELPERS_H_
#define MEDIA_GPU_TEST_BITSTREAM_HELPERS_H_

#include "base/functional/callback.h"
#include "base/memory/ref_counted.h"
#include "base/time/time.h"
#include "media/video/video_encode_accelerator.h"

namespace media {

class DecoderBuffer;

namespace test {

// This class defines an abstract interface for classes that are interested in
// processing bitstreams (e.g. BitstreamValidator, DecoderBufferValidator, ...).
class BitstreamProcessor {
 public:
  struct BitstreamRef : public base::RefCountedThreadSafe<BitstreamRef> {
    static scoped_refptr<BitstreamRef> Create(
        scoped_refptr<DecoderBuffer> buffer,
        const BitstreamBufferMetadata& metadata,
        int32_t id,
        base::TimeTicks source_timestamp,
        base::OnceClosure release_cb);
    BitstreamRef() = delete;
    BitstreamRef(const BitstreamRef&) = delete;
    BitstreamRef& operator=(const BitstreamRef&) = delete;

    const scoped_refptr<DecoderBuffer> buffer;
    const BitstreamBufferMetadata metadata;
    const int32_t id;
    // |source_timestamp| is the timestamp when the VideoFrame for this
    // bitstream is received to an encoder.
    const base::TimeTicks source_timestamp;

   private:
    friend class base::RefCountedThreadSafe<BitstreamRef>;
    BitstreamRef(scoped_refptr<DecoderBuffer> buffer,
                 const BitstreamBufferMetadata& metadata,
                 int32_t id,
                 base::TimeTicks source_timestamp,
                 base::OnceClosure release_cb);
    ~BitstreamRef();

    base::OnceClosure release_cb;
  };

  virtual ~BitstreamProcessor() = default;

  // Process the specified bitstream buffer. This can e.g. validate the
  // buffer's contents or calculate the buffer's checksum.
  virtual void ProcessBitstream(scoped_refptr<BitstreamRef> bitstream,
                                size_t frame_index) = 0;

  // Wait until all currently scheduled bitstream buffers have been processed.
  // Returns whether processing was successful.
  virtual bool WaitUntilDone() = 0;
};

}  // namespace test
}  // namespace media

#endif  // MEDIA_GPU_TEST_BITSTREAM_HELPERS_H_