chromium/media/base/video_types.h

// Copyright 2015 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_BASE_VIDEO_TYPES_H_
#define MEDIA_BASE_VIDEO_TYPES_H_

#include <stdint.h>
#include <iosfwd>
#include <string>

#include "build/build_config.h"
#include "media/base/media_shmem_export.h"

namespace media {

// Pixel formats roughly based on FOURCC labels, see:
// http://www.fourcc.org/rgb.php and http://www.fourcc.org/yuv.php
// Logged to UMA, so never reuse values. Leave gaps if necessary.
// Ordered as planar, semi-planar, YUV-packed, and RGB formats.
// When a VideoFrame is backed by native textures, VideoPixelFormat describes
// how those textures should be sampled and combined to produce the final
// pixels.
enum VideoPixelFormat {};

// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class VideoChromaSampling : uint8_t {};

// Return the name of chroma sampling format as a string.
MEDIA_SHMEM_EXPORT std::string VideoChromaSamplingToString(
    VideoChromaSampling chroma_sampling);

// Returns the name of a Format as a string.
MEDIA_SHMEM_EXPORT std::string VideoPixelFormatToString(
    VideoPixelFormat format);

// Stream operator of Format for logging etc.
MEDIA_SHMEM_EXPORT std::ostream& operator<<(std::ostream& os,
                                            VideoPixelFormat format);

// Returns human readable fourcc string.
// If any of the four characters is non-printable, it outputs
// "0x<32-bit integer in hex>", e.g. FourccToString(0x66616b00) returns
// "0x66616b00".
MEDIA_SHMEM_EXPORT std::string FourccToString(uint32_t fourcc);

// Returns the VideoChromaSampling corresponding to the VideoPixelFormat passed
// in.
MEDIA_SHMEM_EXPORT VideoChromaSampling
VideoPixelFormatToChromaSampling(VideoPixelFormat format);

// Returns true if |format| is a YUV format with multiple planes.
MEDIA_SHMEM_EXPORT bool IsYuvPlanar(VideoPixelFormat format);

// Returns true if |format| is an RGB format.
MEDIA_SHMEM_EXPORT bool IsRGB(VideoPixelFormat format);

// Returns true if |format| has no Alpha channel (hence is always opaque).
MEDIA_SHMEM_EXPORT bool IsOpaque(VideoPixelFormat format);

// Returns the number of significant bits per channel.
MEDIA_SHMEM_EXPORT size_t BitDepth(VideoPixelFormat format);

}  // namespace media

#endif  // MEDIA_BASE_VIDEO_TYPES_H_