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, 2> kAudioCodecNames{
18 {{"aac", AudioCodec::kAac}, {"opus", AudioCodec::kOpus}}};
19
20 constexpr EnumNameTable<VideoCodec, 4> kVideoCodecNames{
21 {{"h264", VideoCodec::kH264},
22 {"vp8", VideoCodec::kVp8},
23 {"hevc", VideoCodec::kHevc},
24 {"vp9", VideoCodec::kVp9}}};
25
26 } // namespace
27
CodecToString(AudioCodec codec)28 const char* CodecToString(AudioCodec codec) {
29 return GetEnumName(kAudioCodecNames, codec).value();
30 }
31
StringToAudioCodec(absl::string_view name)32 ErrorOr<AudioCodec> StringToAudioCodec(absl::string_view name) {
33 return GetEnum(kAudioCodecNames, name);
34 }
35
CodecToString(VideoCodec codec)36 const char* CodecToString(VideoCodec codec) {
37 return GetEnumName(kVideoCodecNames, codec).value();
38 }
39
StringToVideoCodec(absl::string_view name)40 ErrorOr<VideoCodec> StringToVideoCodec(absl::string_view name) {
41 return GetEnum(kVideoCodecNames, name);
42 }
43
44 } // namespace cast
45 } // namespace openscreen
46