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 scoped_refptr<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 make_scoped_refptr(
51  new MediaSample(data, data_size, NULL, 0u, is_key_frame));
52 }
53 
54 // static
55 scoped_refptr<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 make_scoped_refptr(new MediaSample(
63  data, data_size, side_data, side_data_size, is_key_frame));
64 }
65 
66 // static
67 scoped_refptr<MediaSample> MediaSample::FromMetadata(const uint8_t* metadata,
68  size_t metadata_size) {
69  return make_scoped_refptr(
70  new MediaSample(nullptr, 0, metadata, metadata_size, false));
71 }
72 
73 // static
74 scoped_refptr<MediaSample> MediaSample::CreateEmptyMediaSample() {
75  MediaSample* media_sample = new MediaSample();
76  return make_scoped_refptr(media_sample);
77 }
78 
79 // static
80 scoped_refptr<MediaSample> MediaSample::CreateEOSBuffer() {
81  return make_scoped_refptr(new MediaSample(NULL, 0, NULL, 0, false));
82 }
83 
84 std::string MediaSample::ToString() const {
85  if (end_of_stream())
86  return "End of stream sample\n";
87  return base::StringPrintf(
88  "dts: %" PRId64 "\n pts: %" PRId64 "\n duration: %" PRId64 "\n "
89  "is_key_frame: %s\n size: %zu\n side_data_size: %zu\n",
90  dts_,
91  pts_,
92  duration_,
93  is_key_frame_ ? "true" : "false",
94  data_.size(),
95  side_data_.size());
96 }
97 
98 } // namespace media
99 } // namespace shaka
static scoped_refptr< MediaSample > FromMetadata(const uint8_t *metadata, size_t metadata_size)
Definition: media_sample.cc:67
static scoped_refptr< MediaSample > CreateEOSBuffer()
Definition: media_sample.cc:80
std::string ToString() const
Definition: media_sample.cc:84
Class to hold a media sample.
Definition: media_sample.h:21
static scoped_refptr< MediaSample > CopyFrom(const uint8_t *data, size_t size, bool is_key_frame)
Definition: media_sample.cc:45
static scoped_refptr< MediaSample > CreateEmptyMediaSample()
Create a MediaSample object with default members.
Definition: media_sample.cc:74