2
* The contents of this file are subject to the Mozilla Public
3
* License Version 1.1 (the "License"); you may not use this file
4
* except in compliance with the License. You may obtain a copy of
5
* the License at http://www.mozilla.org/MPL/
7
* Software distributed under the License is distributed on an "AS
8
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9
* implied. See the License for the specific language governing
10
* rights and limitations under the License.
12
* The Original Code is MPEG4IP.
14
* The Initial Developer of the Original Code is Cisco Systems Inc.
15
* Portions created by Cisco Systems Inc. are
16
* Copyright (C) Cisco Systems Inc. 2000, 2001. All Rights Reserved.
19
* Bill May wmay@cisco.com
22
* mp4_bytestream.h - provides bytestream access to quicktime files
25
#ifndef __MP4_BYTESTREAM_H__
26
#define __MP4_BYTESTREAM_H__
28
#include <ismacryplib.h>
29
#include "our_bytestream.h"
31
#include "player_util.h"
33
//Uncomment these #defines to dump buffers to file.
34
//#define OUTPUT_TO_FILE 1
35
//#define ISMACRYP_DEBUG 1
38
* CMp4ByteStreamBase provides base class access to quicktime files.
39
* Most functions are shared between audio and video.
41
class CMp4ByteStream : public COurInByteStream
44
CMp4ByteStream(CMp4File *parent,
51
bool start_next_frame(uint8_t **buffer,
53
frame_timestamp_t *pts,
55
void used_bytes_for_frame(uint32_t bytes);
56
int can_skip_frame(void) { return 1; };
57
bool skip_next_frame(frame_timestamp_t *ts, int *hasSyncFrame,
59
uint32_t *buflen, void **ud);
60
void check_for_end_of_frame(void);
61
double get_max_playtime(void);
63
const char *get_inuse_kms_uri(void);
65
void play(uint64_t start);
67
u_int8_t *get_buffer() {return m_buffer; }
68
void set_buffer(u_int8_t *buffer) {
69
memset(m_buffer, 0, m_max_frame_size * sizeof(u_int8_t));
71
uint32_t get_this_frame_size() {return m_this_frame_size;}
72
void set_this_frame_size(uint32_t frame_size)
73
{m_this_frame_size = frame_size;}
83
void read_frame(uint32_t frame, frame_timestamp_t *ts);
87
MP4SampleId m_frames_max;
88
uint32_t m_sample_freq;
90
MP4SampleId m_frame_on;
91
uint64_t m_frame_on_ts;
92
uint32_t m_frame_on_sample_ts;
93
int m_frame_on_has_sync;
95
MP4SampleId m_frame_in_buffer;
96
uint64_t m_frame_in_buffer_ts;
97
int m_frame_in_buffer_has_sync;
99
u_int32_t m_max_frame_size;
102
uint32_t m_this_frame_size;
104
void set_timebase(MP4SampleId frame);
110
* CMp4VideoByteStream is for video streams. It is inherited from
111
* CMp4ByteStreamBase.
113
class CMp4VideoByteStream : public CMp4ByteStream
116
CMp4VideoByteStream(CMp4File *parent,
118
CMp4ByteStream(parent, track, "video", 1) {};
121
class CMp4TextByteStream : public CMp4ByteStream
124
CMp4TextByteStream(CMp4File *parent, MP4TrackId track,
125
const char *base_url) :
126
CMp4ByteStream(parent, track, "cntl", 0) {
127
m_base_url = base_url;
129
~CMp4TextByteStream(void) {
130
//CHECK_AND_FREE(m_base_url);
132
bool start_next_frame(uint8_t **buffer,
134
frame_timestamp_t *ptr,
137
const char *m_base_url;
141
class CMp4H264VideoByteStream : public CMp4VideoByteStream
144
CMp4H264VideoByteStream(CMp4File *parent,
146
CMp4VideoByteStream(parent, track) {
147
m_translate_buffer = NULL;
148
m_translate_buffer_size = 0;
151
bool start_next_frame(uint8_t **buffer,
153
frame_timestamp_t *pts,
156
uint32_t read_nal_size(uint8_t *buffer) {
157
if (m_buflen_size == 1) {
159
} else if (m_buflen_size == 2) {
160
return (buffer[0] << 8) | buffer[1];
161
} else if (m_buflen_size == 3) {
162
return (buffer[0] << 16) | (buffer[1] << 8) | buffer[2];
164
return (buffer[0] << 24) | (buffer[1] << 16) | (buffer[2] << 8) | buffer[3];
166
uint8_t *m_translate_buffer;
167
uint32_t m_translate_buffer_size;
168
uint32_t m_buflen_size;
172
* CMp4AudioByteStream is for audio streams. It is inherited from
173
* CMp4ByteStreamBase.
175
class CMp4AudioByteStream : public CMp4ByteStream
178
CMp4AudioByteStream(CMp4File *parent,
180
CMp4ByteStream(parent, track, "audio", 0) {};
185
* CMp4EncVideoByteStream is for encrypted video streams.
186
* It is inherited from CMp4VideoByteStreamBase.
188
class CMp4EncVideoByteStream : public CMp4VideoByteStream
191
CMp4EncVideoByteStream(CMp4File *parent,
193
uint64_t IVLength ) :
194
CMp4VideoByteStream(parent, track) {
195
ismacryp_rc_t rc = ismacrypInitSession(&m_ismaCryptSId,KeyTypeVideo);
197
if (rc != ismacryp_rc_ok ) {
198
player_error_message("can't initialize video ismacryp session rc: %u\n", rc);
201
rc = ismacrypSetIVLength(m_ismaCryptSId, (uint8_t)IVLength);
202
if( rc != ismacryp_rc_ok )
203
player_error_message(
204
"can't set IV length for ismacryp decode session %d, rc: %u\n",
208
~CMp4EncVideoByteStream() {
209
ismacryp_rc_t rc = ismacrypEndSession(m_ismaCryptSId);
210
if (rc != ismacryp_rc_ok ) {
211
player_error_message(
212
"could not end video ismacryp session %d, rc: %u\n",
216
bool start_next_frame(uint8_t **buffer,
218
frame_timestamp_t *ts,
220
ismacryp_session_id_t m_ismaCryptSId; // eventually make it private
221
// and add accessor function
225
* CMp4EncH264VideoByteStream is for encrypted H264 AVC video streams.
226
* It is inherited from CMp4VideoByteStreamBase.
228
class CMp4EncH264VideoByteStream : public CMp4VideoByteStream
231
CMp4EncH264VideoByteStream(CMp4File *parent,
233
uint64_t IVLength ) :
234
CMp4VideoByteStream(parent, track) {
235
m_translate_buffer = NULL;
236
m_translate_buffer_size = 0;
239
ismacryp_rc_t rc = ismacrypInitSession(&m_ismaCryptSId,KeyTypeVideo);
241
if (rc != ismacryp_rc_ok ) {
242
player_error_message("can't initialize video ismacryp session rc: %u\n", rc);
245
rc = ismacrypSetIVLength(m_ismaCryptSId, (uint8_t)IVLength);
246
if( rc != ismacryp_rc_ok ) {
247
player_error_message(
248
"can't set IV length for ismacryp decode session %d, rc: %u\n",
251
ismacrypGetKMSUri(m_ismaCryptSId, &m_kms_uri);
254
~CMp4EncH264VideoByteStream() {
255
ismacryp_rc_t rc = ismacrypEndSession(m_ismaCryptSId);
256
if (rc != ismacryp_rc_ok ) {
257
player_error_message(
258
"could not end video ismacryp session %d, rc: %u\n",
261
if (m_kms_uri != NULL)
262
free((void *)m_kms_uri);
264
bool start_next_frame(uint8_t **buffer,
266
frame_timestamp_t *ts,
269
const char *get_inuse_kms_uri() { return((const char *)m_kms_uri); }
271
ismacryp_session_id_t m_ismaCryptSId; // eventually make it private
272
// and add accessor function
275
uint32_t read_nal_size(uint8_t *buffer) {
276
if (m_buflen_size == 1) {
278
} else if (m_buflen_size == 2) {
279
return (buffer[0] << 8) | buffer[1];
280
} else if (m_buflen_size == 3) {
281
return (buffer[0] << 16) | (buffer[1] << 8) | buffer[2];
283
return (buffer[0] << 24) | (buffer[1] << 16) | (buffer[2] << 8) | buffer[3];
285
uint8_t *m_translate_buffer;
286
uint32_t m_translate_buffer_size;
287
uint32_t m_buflen_size;
288
const char *m_kms_uri;
292
* CMp4EncAudioByteStream is for encrypted audio streams.
293
* It is inherited from CMp4AudioByteStreamBase.
295
class CMp4EncAudioByteStream : public CMp4AudioByteStream
298
CMp4EncAudioByteStream(CMp4File *parent,
300
uint64_t IVLength ) :
301
CMp4AudioByteStream(parent, track) {
302
ismacryp_rc_t rc = ismacrypInitSession(&m_ismaCryptSId,KeyTypeAudio);
303
if ( rc != ismacryp_rc_ok ) {
304
player_error_message("can't initialize audio ismacryp session rc: %u\n", rc);
307
rc = ismacrypSetIVLength(m_ismaCryptSId, (uint8_t)IVLength);
308
if( rc != ismacryp_rc_ok )
309
player_error_message(
310
"can't set IV length for ismacryp decode session %d, rc: %u\n",
314
~CMp4EncAudioByteStream() {
315
ismacryp_rc_t rc = ismacrypEndSession(m_ismaCryptSId);
316
if ( rc != ismacryp_rc_ok) {
317
player_error_message(
318
"could not end audio ismacryp session %d, rc: %u\n",
322
bool start_next_frame(uint8_t **buffer,
324
frame_timestamp_t *ts,
327
ismacryp_session_id_t m_ismaCryptSId; // eventually make it private
328
// and add accessor function
332
DEFINE_MESSAGE_MACRO(mp4f_message, "mp4file")
334
#define mp4f_message(loglevel, fmt...) message(loglevel, "mp4file", fmt)