DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
media_sample.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/media_sample.h"
8 
9 #include <inttypes.h>
10 
11 #include "packager/base/logging.h"
12 #include "packager/base/strings/stringprintf.h"
13 
14 namespace shaka {
15 namespace media {
16 
17 MediaSample::MediaSample(const uint8_t* data,
18  size_t size,
19  const uint8_t* side_data,
20  size_t side_data_size,
21  bool is_key_frame)
22  : dts_(0),
23  pts_(0),
24  duration_(0),
25  is_key_frame_(is_key_frame),
26  is_encrypted_(false) {
27  if (!data) {
28  CHECK_EQ(size, 0u);
29  }
30 
31  data_.assign(data, data + size);
32  if (side_data)
33  side_data_.assign(side_data, side_data + side_data_size);
34 }
35 
36 MediaSample::MediaSample() : dts_(0),
37  pts_(0),
38  duration_(0),
39  is_key_frame_(false),
40  is_encrypted_(false) {}
41 
42 MediaSample::~MediaSample() {}
43 
44 // static
45 std::shared_ptr<MediaSample> MediaSample::CopyFrom(const uint8_t* data,
46  size_t data_size,
47  bool is_key_frame) {
48  // If you hit this CHECK you likely have a bug in a demuxer. Go fix it.
49  CHECK(data);
50  return std::make_shared<MediaSample>(data, data_size, nullptr, 0u,
51  is_key_frame);
52 }
53 
54 // static
55 std::shared_ptr<MediaSample> MediaSample::CopyFrom(const uint8_t* data,
56  size_t data_size,
57  const uint8_t* side_data,
58  size_t side_data_size,
59  bool is_key_frame) {
60  // If you hit this CHECK you likely have a bug in a demuxer. Go fix it.
61  CHECK(data);
62  return std::make_shared<MediaSample>(data, data_size, side_data,
63  side_data_size, is_key_frame);
64 }
65 
66 // static
67 std::shared_ptr<MediaSample> MediaSample::FromMetadata(const uint8_t* metadata,
68  size_t metadata_size) {
69  return std::make_shared<MediaSample>(nullptr, 0, metadata, metadata_size,
70  false);
71 }
72 
73 // static
74 std::shared_ptr<MediaSample> MediaSample::CreateEmptyMediaSample() {
75  return std::make_shared<MediaSample>();
76 }
77 
78 // static
79 std::shared_ptr<MediaSample> MediaSample::CreateEOSBuffer() {
80  return std::make_shared<MediaSample>(nullptr, 0, nullptr, 0, false);
81 }
82 
83 std::string MediaSample::ToString() const {
84  if (end_of_stream())
85  return "End of stream sample\n";
86  return base::StringPrintf(
87  "dts: %" PRId64 "\n pts: %" PRId64 "\n duration: %" PRId64 "\n "
88  "is_key_frame: %s\n size: %zu\n side_data_size: %zu\n",
89  dts_,
90  pts_,
91  duration_,
92  is_key_frame_ ? "true" : "false",
93  data_.size(),
94  side_data_.size());
95 }
96 
97 } // namespace media
98 } // namespace shaka
static std::shared_ptr< MediaSample > CreateEOSBuffer()
Definition: media_sample.cc:79
static std::shared_ptr< MediaSample > CreateEmptyMediaSample()
Create a MediaSample object with default members.
Definition: media_sample.cc:74
std::string ToString() const
Definition: media_sample.cc:83
static std::shared_ptr< MediaSample > FromMetadata(const uint8_t *metadata, size_t metadata_size)
Definition: media_sample.cc:67
static std::shared_ptr< MediaSample > CopyFrom(const uint8_t *data, size_t size, bool is_key_frame)
Definition: media_sample.cc:45