chromium/media/base/media_serializers.h

// Copyright 2019 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_MEDIA_SERIALIZERS_H_
#define MEDIA_BASE_MEDIA_SERIALIZERS_H_

#include <optional>
#include <sstream>
#include <vector>

#include "base/location.h"
#include "base/strings/stringprintf.h"
#include "media/base/audio_decoder_config.h"
#include "media/base/buffering_state.h"
#include "media/base/cdm_config.h"
#include "media/base/decoder.h"
#include "media/base/media_serializers_base.h"
#include "media/base/renderer.h"
#include "media/base/status.h"
#include "media/base/video_decoder_config.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/hdr_metadata.h"

namespace media::internal {

// Serializing any const or reference combination.
MediaSerializer<const T>;

MediaSerializer<T &>;

// Serialize default value.
template <>
struct MediaSerializer<base::Value> {};

// Serialize list value.
template <>
struct MediaSerializer<base::Value::List> {};

// Serialize vectors of things
MediaSerializer<std::vector<VecType>>;

// Serialize unique pointers
MediaSerializer<std::unique_ptr<T>>;

// serialize optional types
MediaSerializer<std::optional<OptType>>;

// Sometimes raw strings won't template match to a char*.
MediaSerializer<char[len]>;

// Can't send non-finite double values to a base::Value.
template <>
struct MediaSerializer<double> {};

template <>
struct MediaSerializer<int64_t> {};

template <>
struct MediaSerializer<uint32_t> {};

// Just upcast this to get the NaN check.
template <>
struct MediaSerializer<float> {};

// Serialization for chromium-specific types.
// Each serializer should be commented like:
// Class/Enum (simple/complex)
// where Classes should take constref arguments, and "simple" methods should
// be declared inline.

// the FIELD_SERIALIZE method can be used whenever the result is a dict named
// |result|.
#define FIELD_SERIALIZE

// Class (simple)
template <>
struct MediaSerializer<gfx::Size> {};

// Class (simple)
template <>
struct MediaSerializer<gfx::Rect> {};

// enum (simple)
template <>
struct MediaSerializer<base::TimeDelta> {};

// enum (simple)
template <>
struct MediaSerializer<base::Time> {};

// Enum (simple)
template <>
struct MediaSerializer<RendererType> {};

// Enum (simple)
template <>
struct MediaSerializer<VideoDecoderType> {};

// Enum (simple)
template <>
struct MediaSerializer<AudioDecoderType> {};

// Enum (simple)
template <>
struct MediaSerializer<AudioCodec> {};

// Enum (simple)
template <>
struct MediaSerializer<AudioCodecProfile> {};

// Enum (simple)
template <>
struct MediaSerializer<VideoCodec> {};

// Enum (simple)
template <>
struct MediaSerializer<VideoCodecProfile> {};

// Enum (simple)
template <>
struct MediaSerializer<ChannelLayout> {};

// Enum (simple)
template <>
struct MediaSerializer<SampleFormat> {};

// Class (complex)
template <>
struct MediaSerializer<CdmConfig> {};

// Enum (complex)
template <>
struct MediaSerializer<EncryptionScheme> {};

// Class (complex)
template <>
struct MediaSerializer<VideoTransformation> {};

// Class (simple)
template <>
struct MediaSerializer<VideoColorSpace> {};

// Class (complex)
template <>
struct MediaSerializer<gfx::HDRMetadata> {};

// Class (complex)
template <>
struct MediaSerializer<AudioDecoderConfig> {};

// Enum (simple)
template <>
struct MediaSerializer<VideoDecoderConfig::AlphaMode> {};

// Class (complex)
template <>
struct MediaSerializer<VideoDecoderConfig> {};

// enum (simple)
template <>
struct MediaSerializer<BufferingState> {};

// enum (complex)
template <>
struct MediaSerializer<BufferingStateChangeReason> {};

// Class (complex)
MediaSerializer<SerializableBufferingState<T>>;

// Class (complex)
MediaSerializer<TypedStatus<T>>;

// Class (complex)
template <>
struct MediaSerializer<StatusData> {};

// Class (complex)
template <>
struct MediaSerializer<base::Location> {};

#define ENUM_CASE_TO_STRING(ENUM_NAME)

#define ENUM_CLASS_CASE_TO_STRING(ENUM_CLASS, ENUM_NAME)

// Enum (simple)
template <>
struct MediaSerializer<VideoColorSpace::PrimaryID> {};

// Enum (simple)
template <>
struct MediaSerializer<VideoColorSpace::TransferID> {};

// Enum (simple)
template <>
struct MediaSerializer<VideoColorSpace::MatrixID> {};

// Enum (simple)
template <>
struct MediaSerializer<gfx::ColorSpace::RangeID> {};

#undef FIELD_SERIALIZE

}  // namespace media::internal

#endif  // MEDIA_BASE_MEDIA_SERIALIZERS_H_