1 // Copyright 2020 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 #include "cast/streaming/message_fields.h"
6
7 #include <array>
8 #include <utility>
9
10 #include "util/enum_name_table.h"
11 #include "util/osp_logging.h"
12
13 namespace openscreen {
14 namespace cast {
15 namespace {
16
17 constexpr EnumNameTable<AudioCodec, 3> kAudioCodecNames{
18 {{"aac", AudioCodec::kAac},
19 {"opus", AudioCodec::kOpus},
20 {"REMOTE_AUDIO", AudioCodec::kNotSpecified}}};
21
22 constexpr EnumNameTable<VideoCodec, 6> kVideoCodecNames{
23 {{"h264", VideoCodec::kH264},
24 {"vp8", VideoCodec::kVp8},
25 {"hevc", VideoCodec::kHevc},
26 {"REMOTE_VIDEO", VideoCodec::kNotSpecified},
27 {"vp9", VideoCodec::kVp9},
28 {"av1", VideoCodec::kAv1}}};
29
30 } // namespace
31
CodecToString(AudioCodec codec)32 const char* CodecToString(AudioCodec codec) {
33 return GetEnumName(kAudioCodecNames, codec).value();
34 }
35
StringToAudioCodec(absl::string_view name)36 ErrorOr<AudioCodec> StringToAudioCodec(absl::string_view name) {
37 return GetEnum(kAudioCodecNames, name);
38 }
39
CodecToString(VideoCodec codec)40 const char* CodecToString(VideoCodec codec) {
41 return GetEnumName(kVideoCodecNames, codec).value();
42 }
43
StringToVideoCodec(absl::string_view name)44 ErrorOr<VideoCodec> StringToVideoCodec(absl::string_view name) {
45 return GetEnum(kVideoCodecNames, name);
46 }
47
48 } // namespace cast
49 } // namespace openscreen
50