Native Player  1.0
elementary_stream_packet.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 //
3 // Copyright (c) 2016, Samsung Electronics Co., Ltd
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to
7 // deal in the Software without restriction, including without limitation the
8 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 // sell copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM
20 // , OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 // THE SOFTWARE.
22 //
23 // @author Tomasz Borkowski
24 //
25 // ----------------------------------------------------------------------------
26 
27 #ifndef SRC_PLAYER_ES_DASH_PLAYER_DEMUXER_ELEMENTARY_STREAM_PACKET_H_
28 #define SRC_PLAYER_ES_DASH_PLAYER_DEMUXER_ELEMENTARY_STREAM_PACKET_H_
29 
30 #include <vector>
31 
32 #include "nacl_player/media_common.h"
33 
36 
47  public:
55  ElementaryStreamPacket(uint8_t* data, uint32_t size);
56 
58 
63 
65  ~ElementaryStreamPacket() = default;
66 
68 
72 
74  const Samsung::NaClPlayer::ESPacket& GetESPacket() const;
75 
77  const Samsung::NaClPlayer::ESPacketEncryptionInfo& GetEncryptionInfo() const;
78 
80  bool IsEncrypted() const;
81 
84  bool IsKeyFrame() const { return es_packet_.is_key_frame; }
85 
87  uint32_t GetDataSize() const { return data_.size(); }
88 
91  Samsung::NaClPlayer::TimeTicks GetPts() const { return es_packet_.pts; }
92 
95  Samsung::NaClPlayer::TimeTicks GetDts() const { return es_packet_.dts; }
96 
99  Samsung::NaClPlayer::TimeTicks GetDuration() const {
100  return es_packet_.duration;
101  }
102 
105  void SetKeyFrame(bool key_frame) { es_packet_.is_key_frame = key_frame; }
106 
109  void SetPts(Samsung::NaClPlayer::TimeTicks pts) { es_packet_.pts = pts; }
110 
113  void SetDts(Samsung::NaClPlayer::TimeTicks dts) { es_packet_.dts = dts; }
114 
117  void SetDuration(Samsung::NaClPlayer::TimeTicks duration) {
118  es_packet_.duration = duration;
119  }
120 
126  void SetKeyId(uint8_t* key_id, uint32_t key_id_size);
127 
133  void SetIv(uint8_t* iv, uint32_t iv_size);
134 
136  void ClearSubsamples();
137 
144  void AddSubsample(uint32_t clear_bytes, uint32_t cipher_bytes);
145 
146  private:
147  // assumption: Address returned by vector::data() method is invariant under
148  // move operations
149 
150  // invariants:
151 
152  // es_packet.data == data_.data() && es_packet.size == data.size()
153  void FixDataInvariant();
154 
155  // encryption_info.key_id == key_id_.data()
156  // encryption_info.key_id_size == key_id_.size()
157  void FixKeyIdInvariant();
158 
159  // encryption_info.iv == key_id_.data()
160  // encryption_info.iv_size == key_id_.size()
161  void FixIvInvariant();
162 
163  // encryption_info.subsamples == subsamples_.data()
164  // encryption_info.num_subsamples == subsamples_.size()
165  void FixSubsamplesInvariant();
166 
167  std::vector<uint8_t> data_;
168  Samsung::NaClPlayer::ESPacket es_packet_;
169 
170  std::vector<uint8_t> key_id_;
171  std::vector<uint8_t> iv_;
172  std::vector<Samsung::NaClPlayer::EncryptedSubsampleDescription> subsamples_;
173  Samsung::NaClPlayer::ESPacketEncryptionInfo encryption_info_;
174 };
175 
176 #endif // SRC_PLAYER_ES_DASH_PLAYER_DEMUXER_ELEMENTARY_STREAM_PACKET_H_
const Samsung::NaClPlayer::ESPacket & GetESPacket() const
Returns Elementary Stream Packet.
Samsung::NaClPlayer::TimeTicks GetDts() const
void SetDts(Samsung::NaClPlayer::TimeTicks dts)
void SetIv(uint8_t *iv, uint32_t iv_size)
Samsung::NaClPlayer::TimeTicks GetPts() const
void SetDuration(Samsung::NaClPlayer::TimeTicks duration)
uint32_t GetDataSize() const
Returns size of packet&#39;s data.
void SetKeyFrame(bool key_frame)
ElementaryStreamPacket & operator=(const ElementaryStreamPacket &)=delete
ElementaryStreamPacket(uint8_t *data, uint32_t size)
~ElementaryStreamPacket()=default
Destroys ElementaryStreamPacket object.
void AddSubsample(uint32_t clear_bytes, uint32_t cipher_bytes)
void SetKeyId(uint8_t *key_id, uint32_t key_id_size)
This class is a wrapper for both Samsung::NaClPlayer::ESPacket and encryption information.
const Samsung::NaClPlayer::ESPacketEncryptionInfo & GetEncryptionInfo() const
Returns Encryption information.
Samsung::NaClPlayer::TimeTicks GetDuration() const
bool IsEncrypted() const
Returns true if packet is encrypted, otherwise false.
void ClearSubsamples()
Clears the subsample information about encrypted bytes in packet.
void SetPts(Samsung::NaClPlayer::TimeTicks pts)