blob: 42231368615e7b703d25234516879105e422c609 [file] [log] [blame]
// Copyright 2018 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef GARNET_EXAMPLES_MEDIA_USE_MEDIA_DECODER_USE_VIDEO_DECODER_H_
#define GARNET_EXAMPLES_MEDIA_USE_MEDIA_DECODER_USE_VIDEO_DECODER_H_
#include <fuchsia/mediacodec/cpp/fidl.h>
#include <lib/async-loop/cpp/loop.h>
#include <openssl/sha.h>
#include <stdint.h>
class FrameSink;
// use_h264_decoder()
//
// If anything goes wrong, exit(-1) is used directly (until we have any reason
// to do otherwise).
//
// On success, the return value is the sha256 of the output data. This is
// intended as a golden-file value when this function is used as part of a test.
// This sha256 value accounts for all the output payload data and also the
// output format parameters. When the same input file is decoded we expect the
// sha256 to be the same.
//
// main_loop - the loop run by main(). The codec_factory is bound to
// main_loop->dispatcher().
// codec_factory - codec_factory to take ownership of, use, and close by the
// time the function returns.
// input_file - This must be set and must be the filename of an input h264
// file (input file extension not checked / doesn't matter).
// output_file - If nullptr, don't write the data to an output file. If
// non-nullptr, output uncompressed data to the specified file. When used
// as an example, this will tend to be set. When used as a test, this will
// not be set.
// md_out - out sha256 of the ordered output frame pixels and ordered output
// format details.
// timestamps_out - out ordered <has_timestamp_ish, timestamp_ish> seen at the
// output of the decoder.
// fourcc - if not nullptr, sets the value to the fourcc of the decoded frames.
// frame_sink - if not nullptr, send each frame to this FrameSink, which will
// call back when the frame has been released by the sink.
void use_h264_decoder(async::Loop* main_loop,
fuchsia::mediacodec::CodecFactoryPtr codec_factory,
fidl::InterfaceHandle<fuchsia::sysmem::Allocator> sysmem,
const std::string& input_file,
const std::string& output_file,
uint8_t md_out[SHA256_DIGEST_LENGTH],
std::vector<std::pair<bool, uint64_t>>* timestamps_out,
uint32_t* fourcc, FrameSink* frame_sink);
// The same as use_h264_decoder, but for a VP9 file wrapped in an IVF container.
void use_vp9_decoder(async::Loop* main_loop,
fuchsia::mediacodec::CodecFactoryPtr codec_factory,
fidl::InterfaceHandle<fuchsia::sysmem::Allocator> sysmem,
const std::string& input_file,
const std::string& output_file,
uint8_t md_out[SHA256_DIGEST_LENGTH],
std::vector<std::pair<bool, uint64_t>>* timestamps_out,
FrameSink* frame_sink);
#endif // GARNET_EXAMPLES_MEDIA_USE_MEDIA_DECODER_USE_VIDEO_DECODER_H_