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#include <cstddef>
11#include <cstdint>
12#include <string>
13
14#include <absl/strings/str_format.h>
15
16#include <packager/macros/logging.h>
17#include <packager/media/base/timestamp.h>
18
19namespace shaka {
20namespace media {
21
22std::string StreamTypeToString(StreamType type) {
23 switch (type) {
24 case kStreamUnknown:
25 return "Unknown";
26 case kStreamVideo:
27 return "Video";
28 case kStreamAudio:
29 return "Audio";
30 case kStreamText:
31 return "Text";
32 }
33
34 NOTIMPLEMENTED() << "Unhandled StreamType with value "
35 << static_cast<int>(type);
36 return "";
37}
38
39StreamInfo::StreamInfo(StreamType stream_type,
40 int track_id,
41 int32_t time_scale,
42 int64_t duration,
43 Codec codec,
44 const std::string& codec_string,
45 const uint8_t* codec_config,
46 size_t codec_config_size,
47 const std::string& language,
48 bool is_encrypted)
49 : stream_type_(stream_type),
50 track_id_(track_id),
51 time_scale_(time_scale),
52 duration_(duration),
53 codec_(codec),
54 codec_string_(codec_string),
55 language_(language),
56 is_encrypted_(is_encrypted) {
57 if (codec_config_size > 0) {
58 codec_config_.assign(codec_config, codec_config + codec_config_size);
59 }
60}
61
62StreamInfo::~StreamInfo() {}
63
64std::string StreamInfo::ToString() const {
65 std::string duration;
66 if (duration_ == kInfiniteDuration) {
67 duration = "Infinite";
68 } else {
69 duration = absl::StrFormat("%" PRIu64 " (%.1f seconds)", duration_,
70 static_cast<double>(duration_) / time_scale_);
71 }
72
73 return absl::StrFormat(
74 "type: %s\n codec_string: %s\n time_scale: %d\n duration: "
75 "%s\n is_encrypted: %s\n",
76 StreamTypeToString(stream_type_).c_str(), codec_string_.c_str(),
77 time_scale_, duration.c_str(), is_encrypted_ ? "true" : "false");
78}
79
80} // namespace media
81} // namespace shaka
All the methods that are virtual are virtual for mocking.