Shaka Packager SDK
Loading...
Searching...
No Matches
stream_info.cc
1// Copyright 2014 Google LLC. All rights reserved.
2//
3// Use of this source code is governed by a BSD-style
4// license that can be found in the LICENSE file or at
5// https://developers.google.com/open-source/licenses/bsd
6
7#include <packager/media/base/stream_info.h>
8
9#include <cinttypes>
10
11#include <absl/log/log.h>
12#include <absl/strings/str_format.h>
13
14#include <packager/macros/logging.h>
15#include <packager/media/base/timestamp.h>
16
17namespace shaka {
18namespace media {
19
20std::string StreamTypeToString(StreamType type) {
21 switch (type) {
22 case kStreamUnknown:
23 return "Unknown";
24 case kStreamVideo:
25 return "Video";
26 case kStreamAudio:
27 return "Audio";
28 case kStreamText:
29 return "Text";
30 }
31
32 NOTIMPLEMENTED() << "Unhandled StreamType with value "
33 << static_cast<int>(type);
34 return "";
35}
36
37StreamInfo::StreamInfo(StreamType stream_type,
38 int track_id,
39 int32_t time_scale,
40 int64_t duration,
41 Codec codec,
42 const std::string& codec_string,
43 const uint8_t* codec_config,
44 size_t codec_config_size,
45 const std::string& language,
46 bool is_encrypted)
47 : stream_type_(stream_type),
48 track_id_(track_id),
49 time_scale_(time_scale),
50 duration_(duration),
51 codec_(codec),
52 codec_string_(codec_string),
53 language_(language),
54 is_encrypted_(is_encrypted) {
55 if (codec_config_size > 0) {
56 codec_config_.assign(codec_config, codec_config + codec_config_size);
57 }
58}
59
60StreamInfo::~StreamInfo() {}
61
62std::string StreamInfo::ToString() const {
63 std::string duration;
64 if (duration_ == kInfiniteDuration) {
65 duration = "Infinite";
66 } else {
67 duration = absl::StrFormat("%" PRIu64 " (%.1f seconds)", duration_,
68 static_cast<double>(duration_) / time_scale_);
69 }
70
71 return absl::StrFormat(
72 "type: %s\n codec_string: %s\n time_scale: %d\n duration: "
73 "%s\n is_encrypted: %s\n",
74 StreamTypeToString(stream_type_).c_str(), codec_string_.c_str(),
75 time_scale_, duration.c_str(), is_encrypted_ ? "true" : "false");
76}
77
78} // namespace media
79} // namespace shaka
All the methods that are virtual are virtual for mocking.