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