Kieran Kunhya 2012-02-18 23:51:53 +00:00
rodzic 4a0d349eda
commit c5d276966f
14 zmienionych plików z 1281 dodań i 1281 usunięć

28
README
Wyświetl plik

@ -1,14 +1,14 @@
libmpegts README libmpegts README
Single Program Transport stream muxer Single Program Transport stream muxer
Things which work: Things which work:
CBR and VBR TS muxing of AVC, AC-3, MP2 and AAC/HE-AAC. CBR and VBR TS muxing of AVC, AC-3, MP2 and AAC/HE-AAC.
DVB AU_Information DVB AU_Information
(Very likely MPEG-2 as well but not tested) (Very likely MPEG-2 as well but not tested)
Things which don't work: Things which don't work:
Blu-Ray and associated formats Blu-Ray and associated formats
DTS DTS

24
TODO
Wyświetl plik

@ -1,12 +1,12 @@
libmpegts TODO list libmpegts TODO list
Most important TODO is to get streams verified with a good analyzer Most important TODO is to get streams verified with a good analyzer
Is there a need to implement full T-STD modelling or use the simpler version currently implemented? Is there a need to implement full T-STD modelling or use the simpler version currently implemented?
Do we need to control EB buffer fullness more? Do we need to control EB buffer fullness more?
Find out why some streams where muxrate is larger than TB leak rate fail to mux. Find out why some streams where muxrate is larger than TB leak rate fail to mux.
A true VBR mode? How to implement? Within Spec? A true VBR mode? How to implement? Within Spec?
Write ATSC PSIP Write ATSC PSIP
Write DVB Tables (SIT, NIT, EIT) etc Write DVB Tables (SIT, NIT, EIT) etc
Sort out T-STD on Data streams Sort out T-STD on Data streams
Add more formats Add more formats
Add Blu-ray formats - dealing with vbr audio? Add Blu-ray formats - dealing with vbr audio?

Wyświetl plik

@ -1,75 +1,75 @@
/***************************************************************************** /*****************************************************************************
* atsc.c : ATSC specific functions * atsc.c : ATSC specific functions
***************************************************************************** *****************************************************************************
* Copyright (C) 2010 Kieran Kunhya * Copyright (C) 2010 Kieran Kunhya
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
*****************************************************************************/ *****************************************************************************/
#include "../common.h" #include "../common.h"
#include "atsc.h" #include "atsc.h"
/* Second Loop of PMT */ /* Second Loop of PMT */
void parse_ac3_frame( ts_atsc_ac3_info *atsc_ac3_ctx, uint8_t *frame ) void parse_ac3_frame( ts_atsc_ac3_info *atsc_ac3_ctx, uint8_t *frame )
{ {
atsc_ac3_ctx->sample_rate_code = frame[4] >> 6; atsc_ac3_ctx->sample_rate_code = frame[4] >> 6;
atsc_ac3_ctx->bsid = frame[5] >> 3; atsc_ac3_ctx->bsid = frame[5] >> 3;
atsc_ac3_ctx->bit_rate_code = (frame[4] & 0x3f) >> 1; atsc_ac3_ctx->bit_rate_code = (frame[4] & 0x3f) >> 1;
atsc_ac3_ctx->surround_mode = (frame[6] & 1) << 1 | (frame[7] >> 7); atsc_ac3_ctx->surround_mode = (frame[6] & 1) << 1 | (frame[7] >> 7);
atsc_ac3_ctx->bsmod = frame[5] & 0x7; atsc_ac3_ctx->bsmod = frame[5] & 0x7;
atsc_ac3_ctx->num_channels = frame[6] >> 5; atsc_ac3_ctx->num_channels = frame[6] >> 5;
} }
void write_atsc_ac3_descriptor( bs_t *s, ts_atsc_ac3_info *atsc_ac3_ctx ) void write_atsc_ac3_descriptor( bs_t *s, ts_atsc_ac3_info *atsc_ac3_ctx )
{ {
bs_write( s, 8, ATSC_AC3_DESCRIPTOR_TAG ); // descriptor_tag bs_write( s, 8, ATSC_AC3_DESCRIPTOR_TAG ); // descriptor_tag
bs_write( s, 8, 3 ); // descriptor_length bs_write( s, 8, 3 ); // descriptor_length
bs_write( s, 3, atsc_ac3_ctx->sample_rate_code ); // sample_rate_code bs_write( s, 3, atsc_ac3_ctx->sample_rate_code ); // sample_rate_code
bs_write( s, 5, atsc_ac3_ctx->bsid ); // bsid bs_write( s, 5, atsc_ac3_ctx->bsid ); // bsid
bs_write( s, 6, atsc_ac3_ctx->bit_rate_code ); // bit_rate_code bs_write( s, 6, atsc_ac3_ctx->bit_rate_code ); // bit_rate_code
bs_write( s, 2, atsc_ac3_ctx->surround_mode ); // surround_mode bs_write( s, 2, atsc_ac3_ctx->surround_mode ); // surround_mode
bs_write( s, 3, atsc_ac3_ctx->bsmod ); // bsmod bs_write( s, 3, atsc_ac3_ctx->bsmod ); // bsmod
bs_write( s, 4, atsc_ac3_ctx->num_channels ); // num_channels bs_write( s, 4, atsc_ac3_ctx->num_channels ); // num_channels
bs_write1( s, 1 ); // full_svc bs_write1( s, 1 ); // full_svc
} }
/* Also in EIT */ /* Also in EIT */
// FIXME fill in the blanks // FIXME fill in the blanks
void write_caption_service_descriptor( bs_t *s ) void write_caption_service_descriptor( bs_t *s )
{ {
bs_write( s, 8, ATSC_CAPTION_SERVICE_DESCRIPTOR_TAG ); // descriptor_tag bs_write( s, 8, ATSC_CAPTION_SERVICE_DESCRIPTOR_TAG ); // descriptor_tag
bs_write( s, 8, 0 ); // descriptor_length bs_write( s, 8, 0 ); // descriptor_length
bs_write( s, 3, 0x7 ); // reserved bs_write( s, 3, 0x7 ); // reserved
bs_write( s, 5, 0 ); // number_of_services bs_write( s, 5, 0 ); // number_of_services
for( int i = 0; i < 0; i++ ) for( int i = 0; i < 0; i++ )
{ {
bs_write( s, 8, 0 ); // language[0] bs_write( s, 8, 0 ); // language[0]
bs_write( s, 8, 0 ); // language[1] bs_write( s, 8, 0 ); // language[1]
bs_write( s, 8, 0 ); // language[2] bs_write( s, 8, 0 ); // language[2]
bs_write1( s, 0 ); // digital_cc bs_write1( s, 0 ); // digital_cc
bs_write1( s, 1 ); // reserved bs_write1( s, 1 ); // reserved
if( 0 ) if( 0 )
bs_write( s, 6, 0x3f ); // reserved bs_write( s, 6, 0x3f ); // reserved
else else
bs_write( s, 6, 0 ); // caption_service_number bs_write( s, 6, 0 ); // caption_service_number
bs_write1( s, 0 ); // easy_reader bs_write1( s, 0 ); // easy_reader
bs_write1( s, 0 ); // wide_aspect_ratio bs_write1( s, 0 ); // wide_aspect_ratio
bs_write( s, 13, 0x3fff ); // reserved bs_write( s, 13, 0x3fff ); // reserved
} }
} }

Wyświetl plik

@ -1,37 +1,37 @@
/***************************************************************************** /*****************************************************************************
* atsc.h : ATSC specific headers * atsc.h : ATSC specific headers
***************************************************************************** *****************************************************************************
* Copyright (C) 2010 Kieran Kunhya * Copyright (C) 2010 Kieran Kunhya
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
*****************************************************************************/ *****************************************************************************/
#ifndef LIBMPEGTS_ATSC_H #ifndef LIBMPEGTS_ATSC_H
#define LIBMPEGTS_ATSC_H #define LIBMPEGTS_ATSC_H
/* ATSC stream_types */ /* ATSC stream_types */
#define AUDIO_AC3 0x81 #define AUDIO_AC3 0x81
#define AUDIO_EAC3 0x84 #define AUDIO_EAC3 0x84
/* Descriptors */ /* Descriptors */
#define ATSC_AC3_DESCRIPTOR_TAG 0x81 #define ATSC_AC3_DESCRIPTOR_TAG 0x81
#define ATSC_CAPTION_SERVICE_DESCRIPTOR_TAG 0x86 #define ATSC_CAPTION_SERVICE_DESCRIPTOR_TAG 0x86
#define ATSC_EXTENDED_CHANNEL_NAME_DESCRIPTOR_TAG 0xa0 #define ATSC_EXTENDED_CHANNEL_NAME_DESCRIPTOR_TAG 0xa0
void parse_ac3_frame( ts_atsc_ac3_info *atsc_ac3_ctx, uint8_t *frame ); void parse_ac3_frame( ts_atsc_ac3_info *atsc_ac3_ctx, uint8_t *frame );
void write_atsc_ac3_descriptor( bs_t *s, ts_atsc_ac3_info *atsc_ac3_ctx ); void write_atsc_ac3_descriptor( bs_t *s, ts_atsc_ac3_info *atsc_ac3_ctx );
void write_caption_service_descriptor( bs_t *s ); void write_caption_service_descriptor( bs_t *s );
#endif #endif

Wyświetl plik

@ -1,40 +1,40 @@
/***************************************************************************** /*****************************************************************************
* cablelabs.c : CableLabs (includes SCTE) specific functions * cablelabs.c : CableLabs (includes SCTE) specific functions
***************************************************************************** *****************************************************************************
* Copyright (C) 2010 Kieran Kunhya * Copyright (C) 2010 Kieran Kunhya
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
*****************************************************************************/ *****************************************************************************/
#include "../common.h" #include "../common.h"
#include "cablelabs.h" #include "cablelabs.h"
/**** First Loop of PMT Descriptors ****/ /**** First Loop of PMT Descriptors ****/
/* 3D descriptor */ /* 3D descriptor */
void write_cablelabs_3d_descriptor( bs_t *s ) void write_cablelabs_3d_descriptor( bs_t *s )
{ {
bs_write( s, 8, CABLELABS_3D_MPEG2_DESCRIPTOR_TAG ); // descriptor_tag bs_write( s, 8, CABLELABS_3D_MPEG2_DESCRIPTOR_TAG ); // descriptor_tag
bs_write( s, 8, 1 ); // descriptor_length bs_write( s, 8, 1 ); // descriptor_length
bs_write1( s, 1 ); // 3d_frame_packing_data_present bs_write1( s, 1 ); // 3d_frame_packing_data_present
bs_write( s, 7, 0 ); // reserved bs_write( s, 7, 0 ); // reserved
} }
/**** Second Loop of PMT Descriptors ****/ /**** Second Loop of PMT Descriptors ****/
/* Adaptation Descriptor */ /* Adaptation Descriptor */
void write_scte_adaptation_descriptor( bs_t *s ) void write_scte_adaptation_descriptor( bs_t *s )
{ {
bs_write( s, 8, SCTE_ADAPTATION_FIELD_DESCRIPTOR_TAG ); // descriptor_tag bs_write( s, 8, SCTE_ADAPTATION_FIELD_DESCRIPTOR_TAG ); // descriptor_tag
bs_write( s, 8, 0 ); // descriptor_length bs_write( s, 8, 0 ); // descriptor_length
} }

Wyświetl plik

@ -1,31 +1,31 @@
/***************************************************************************** /*****************************************************************************
* cablelabs.h : CableLabs (includes SCTE) specific headers * cablelabs.h : CableLabs (includes SCTE) specific headers
***************************************************************************** *****************************************************************************
* Copyright (C) 2010 Kieran Kunhya * Copyright (C) 2010 Kieran Kunhya
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
*****************************************************************************/ *****************************************************************************/
#ifndef LIBMPEGTS_CABLELABS_H #ifndef LIBMPEGTS_CABLELABS_H
#define LIBMPEGTS_CABLELABS_H #define LIBMPEGTS_CABLELABS_H
/* Descriptors */ /* Descriptors */
#define SCTE_ADAPTATION_FIELD_DESCRIPTOR_TAG 0x97 #define SCTE_ADAPTATION_FIELD_DESCRIPTOR_TAG 0x97
#define CABLELABS_3D_MPEG2_DESCRIPTOR_TAG 0xe8 #define CABLELABS_3D_MPEG2_DESCRIPTOR_TAG 0xe8
void write_cablelabs_3d_descriptor( bs_t *s ); void write_cablelabs_3d_descriptor( bs_t *s );
void write_scte_adaptation_descriptor( bs_t *s ); void write_scte_adaptation_descriptor( bs_t *s );
#endif #endif

716
common.h
Wyświetl plik

@ -1,358 +1,358 @@
/***************************************************************************** /*****************************************************************************
* common.h : common data * common.h : common data
***************************************************************************** *****************************************************************************
* Copyright (C) 2010 Kieran Kunhya * Copyright (C) 2010 Kieran Kunhya
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
*****************************************************************************/ *****************************************************************************/
#ifndef LIBMPEGTS_COMMON_H #ifndef LIBMPEGTS_COMMON_H
#define LIBMPEGTS_COMMON_H #define LIBMPEGTS_COMMON_H
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#if HAVE_STDINT_H #if HAVE_STDINT_H
#include <stdint.h> #include <stdint.h>
#else #else
#include <inttypes.h> #include <inttypes.h>
#endif #endif
#include "bitstream.h" #include "bitstream.h"
#include "libmpegts.h" #include "libmpegts.h"
#include <string.h> #include <string.h>
/* Standardised Audio/Video stream_types */ /* Standardised Audio/Video stream_types */
#define VIDEO_MPEG2 0x02 #define VIDEO_MPEG2 0x02
#define VIDEO_AVC 0x1b #define VIDEO_AVC 0x1b
#define AUDIO_MPEG1 0x03 #define AUDIO_MPEG1 0x03
#define AUDIO_MPEG2 0x04 #define AUDIO_MPEG2 0x04
#define AUDIO_ADTS 0x0f #define AUDIO_ADTS 0x0f
#define AUDIO_LATM 0x11 #define AUDIO_LATM 0x11
#define PRIVATE_SECTION 0x05 #define PRIVATE_SECTION 0x05
#define PRIVATE_DATA 0x06 #define PRIVATE_DATA 0x06
#define TS_HEADER_SIZE 4 #define TS_HEADER_SIZE 4
#define TS_PACKET_SIZE 188 #define TS_PACKET_SIZE 188
#define TS_CLOCK 27000000LL #define TS_CLOCK 27000000LL
#define TS_START 10 #define TS_START 10
// arbitrary // arbitrary
#define MAX_PROGRAMS 100 #define MAX_PROGRAMS 100
#define MAX_STREAMS 100 #define MAX_STREAMS 100
/* DVB 40ms recommendation */ /* DVB 40ms recommendation */
#define PCR_MAX_RETRANS_TIME 40 #define PCR_MAX_RETRANS_TIME 40
#define PAT_MAX_RETRANS_TIME 100 #define PAT_MAX_RETRANS_TIME 100
/* PIDs */ /* PIDs */
#define PAT_PID 0x0000 #define PAT_PID 0x0000
#define NIT_PID 0x0010 #define NIT_PID 0x0010
#define SIT_PID 0x001f #define SIT_PID 0x001f
#define NULL_PID 0xffff #define NULL_PID 0xffff
/* TIDs */ /* TIDs */
#define PAT_TID 0x00 #define PAT_TID 0x00
#define PMT_TID 0x02 #define PMT_TID 0x02
#define NIT_TID 0x40 #define NIT_TID 0x40
#define SIT_TID 0x7f #define SIT_TID 0x7f
/* NIT */ /* NIT */
/* ETSI TS 101 162 - Temporary Private Use /* ETSI TS 101 162 - Temporary Private Use
* Used for both "Original Network ID" and "Network ID" */ * Used for both "Original Network ID" and "Network ID" */
#define DEFAULT_NID 0xff01 #define DEFAULT_NID 0xff01
/* Program and Program Element Descriptor Tags */ /* Program and Program Element Descriptor Tags */
#define VIDEO_STREAM_DESCRIPTOR_TAG 0x2 #define VIDEO_STREAM_DESCRIPTOR_TAG 0x2
#define AUDIO_STREAM_DESCRIPTOR_TAG 0x3 #define AUDIO_STREAM_DESCRIPTOR_TAG 0x3
#define REGISTRATION_DESCRIPTOR_TAG 0x5 #define REGISTRATION_DESCRIPTOR_TAG 0x5
#define DATA_STREAM_ALIGNMENT_DESCRIPTOR_TAG 0x6 #define DATA_STREAM_ALIGNMENT_DESCRIPTOR_TAG 0x6
#define ISO_693_LANGUAGE_DESCRIPTOR_TAG 0xa #define ISO_693_LANGUAGE_DESCRIPTOR_TAG 0xa
#define PRIVATE_DATA_DESCRIPTOR_TAG 0xe #define PRIVATE_DATA_DESCRIPTOR_TAG 0xe
#define SMOOTHING_BUFFER_DESCRIPTOR_TAG 0x10 #define SMOOTHING_BUFFER_DESCRIPTOR_TAG 0x10
#define AVC_DESCRIPTOR_TAG 0x28 #define AVC_DESCRIPTOR_TAG 0x28
#define MPEG2_AAC_AUDIO_DESCRIPTOR 0x2b #define MPEG2_AAC_AUDIO_DESCRIPTOR 0x2b
#define SVC_EXTENSION_DESCRIPTOR_TAG 0x30 #define SVC_EXTENSION_DESCRIPTOR_TAG 0x30
#define MVC_EXTENSION_DESCRIPTOR_TAG 0x31 #define MVC_EXTENSION_DESCRIPTOR_TAG 0x31
#define USER_DEFINED_DESCRIPTOR_TAG 0xc4 #define USER_DEFINED_DESCRIPTOR_TAG 0xc4
#define TB_SIZE 4096 #define TB_SIZE 4096
#define RX_SYS 1000000 #define RX_SYS 1000000
#define R_SYS_DEFAULT 80000 #define R_SYS_DEFAULT 80000
/* Macros */ /* Macros */
#define BOOLIFY(x) x = !!x #define BOOLIFY(x) x = !!x
#define MIN(a,b) ( (a)<(b) ? (a) : (b) ) #define MIN(a,b) ( (a)<(b) ? (a) : (b) )
#define MAX(a,b) ( (a)>(b) ? (a) : (b) ) #define MAX(a,b) ( (a)>(b) ? (a) : (b) )
#define IS_VIDEO(x) ( x->stream_format == LIBMPEGTS_VIDEO_MPEG2 || x->stream_format == LIBMPEGTS_VIDEO_AVC ) #define IS_VIDEO(x) ( x->stream_format == LIBMPEGTS_VIDEO_MPEG2 || x->stream_format == LIBMPEGTS_VIDEO_AVC )
/* Internal Program & Stream Structures */ /* Internal Program & Stream Structures */
typedef struct typedef struct
{ {
int level; int level;
int profile; int profile;
int frame_rate; int frame_rate;
} mpegvideo_stream_ctx_t; } mpegvideo_stream_ctx_t;
typedef struct typedef struct
{ {
int num_channels; int num_channels;
int sample_rate; int sample_rate;
int bits_per_sample; int bits_per_sample;
} lpcm_stream_ctx_t; } lpcm_stream_ctx_t;
typedef struct typedef struct
{ {
int frame_rate; int frame_rate;
int aspect_ratio; int aspect_ratio;
} hdmv_video_stream_ctx_t; } hdmv_video_stream_ctx_t;
typedef struct typedef struct
{ {
int sample_rate_code; int sample_rate_code;
int bsid; int bsid;
int bit_rate_code; int bit_rate_code;
int surround_mode; int surround_mode;
int bsmod; int bsmod;
int num_channels; int num_channels;
} ts_atsc_ac3_info; } ts_atsc_ac3_info;
/* Blu-Ray DTCP */ /* Blu-Ray DTCP */
typedef struct typedef struct
{ {
uint8_t byte_1; uint8_t byte_1;
uint8_t byte_2; uint8_t byte_2;
} ts_dtcp_t; } ts_dtcp_t;
typedef struct typedef struct
{ {
/* in bytes */ /* in bytes */
int adapt_field_size; int adapt_field_size;
int pes_header_size; int pes_header_size;
int cur_pos; int cur_pos;
} buffer_queue_t; } buffer_queue_t;
typedef struct typedef struct
{ {
int buf_size; /* size of buffer */ int buf_size; /* size of buffer */
int cur_buf; /* current buffer fill */ int cur_buf; /* current buffer fill */
double last_byte_removal_time; double last_byte_removal_time;
buffer_queue_t queued_packets[10]; buffer_queue_t queued_packets[10];
} buffer_t; } buffer_t;
typedef struct typedef struct
{ {
int pid; int pid;
int cc; int cc;
int stream_format; /* internal stream format type */ int stream_format; /* internal stream format type */
int stream_type; /* stream_type syntax element */ int stream_type; /* stream_type syntax element */
int stream_id; int stream_id;
int version_number; int version_number;
int64_t last_pkt_pcr; int64_t last_pkt_pcr;
/* Stream contexts */ /* Stream contexts */
mpegvideo_stream_ctx_t *mpegvideo_ctx; mpegvideo_stream_ctx_t *mpegvideo_ctx;
lpcm_stream_ctx_t *lpcm_ctx; lpcm_stream_ctx_t *lpcm_ctx;
ts_atsc_ac3_info *atsc_ac3_ctx; ts_atsc_ac3_info *atsc_ac3_ctx;
int num_dvb_sub; int num_dvb_sub;
ts_dvb_sub_t *dvb_sub_ctx; ts_dvb_sub_t *dvb_sub_ctx;
int num_dvb_ttx; int num_dvb_ttx;
ts_dvb_ttx_t *dvb_ttx_ctx; ts_dvb_ttx_t *dvb_ttx_ctx;
int num_dvb_vbi; int num_dvb_vbi;
ts_dvb_vbi_t *dvb_vbi_ctx; ts_dvb_vbi_t *dvb_vbi_ctx;
int num_channels; int num_channels;
int max_frame_size; int max_frame_size;
/* T_STD */ /* T_STD */
buffer_t tb; /* transport buffer */ buffer_t tb; /* transport buffer */
int rx; /* flow from transport to multiplex buffer (video) or main buffer (audio) */ int rx; /* flow from transport to multiplex buffer (video) or main buffer (audio) */
buffer_t mb; /* multiplex buffer (video) or main buffer (audio) */ buffer_t mb; /* multiplex buffer (video) or main buffer (audio) */
buffer_t eb; /* elementary buffer */ buffer_t eb; /* elementary buffer */
int rbx; /* flow from multiplex to elementary buffer (video) */ int rbx; /* flow from multiplex to elementary buffer (video) */
/* Language Codes */ /* Language Codes */
int write_lang_code; int write_lang_code;
char lang_code[4]; char lang_code[4];
int audio_type; int audio_type;
/* AAC */ /* AAC */
int aac_is_mpeg4; int aac_is_mpeg4;
int aac_profile; int aac_profile;
int aac_channel_map; int aac_channel_map;
/* ATSC */ /* ATSC */
/* DVB */ /* DVB */
/* Stream Identifier */ /* Stream Identifier */
int has_stream_identifier; int has_stream_identifier;
int stream_identifier; int stream_identifier;
/* DVB AU_Information */ /* DVB AU_Information */
int dvb_au; int dvb_au;
int dvb_au_frame_rate; int dvb_au_frame_rate;
/* ISDB */ /* ISDB */
/* CableLabs */ /* CableLabs */
/* Blu-Ray */ /* Blu-Ray */
int hdmv_video_format; int hdmv_video_format;
int hdmv_frame_rate; int hdmv_frame_rate;
int hdmv_aspect_ratio; int hdmv_aspect_ratio;
} ts_int_stream_t; } ts_int_stream_t;
typedef struct typedef struct
{ {
uint8_t *data; uint8_t *data;
int size; int size;
uint8_t *cur_pos; uint8_t *cur_pos;
int bytes_left; int bytes_left;
/* stream context associated with pes */ /* stream context associated with pes */
ts_int_stream_t *stream; ts_int_stream_t *stream;
int header_size; int header_size;
int random_access; int random_access;
int priority; int priority;
int64_t cpb_initial_arrival_time; int64_t cpb_initial_arrival_time;
int64_t cpb_final_arrival_time; int64_t cpb_final_arrival_time;
int64_t dts; int64_t dts;
int64_t pts; int64_t pts;
/* DVB AU_Information specific fields */ /* DVB AU_Information specific fields */
uint8_t frame_type; uint8_t frame_type;
int ref_pic_idc; int ref_pic_idc;
int write_pulldown_info; int write_pulldown_info;
int pic_struct; int pic_struct;
} ts_int_pes_t; } ts_int_pes_t;
typedef struct typedef struct
{ {
ts_int_stream_t pmt; ts_int_stream_t pmt;
int program_num; int program_num;
int num_queued_pmt; int num_queued_pmt;
uint8_t **pmt_packets; uint8_t **pmt_packets;
int num_streams; int num_streams;
ts_int_stream_t *streams[MAX_STREAMS]; ts_int_stream_t *streams[MAX_STREAMS];
ts_int_stream_t *pcr_stream; ts_int_stream_t *pcr_stream;
int pmt_version; int pmt_version;
uint64_t last_pcr; uint64_t last_pcr;
int64_t video_dts; int64_t video_dts;
//sdt_program_ctx_t *sdt_ctx; //sdt_program_ctx_t *sdt_ctx;
int is_3dtv; int is_3dtv;
int sb_leak_rate; int sb_leak_rate;
int sb_size; int sb_size;
} ts_int_program_t; } ts_int_program_t;
struct ts_writer_t struct ts_writer_t
{ {
struct struct
{ {
int i_bitstream; int i_bitstream;
uint8_t *p_bitstream; uint8_t *p_bitstream;
bs_t bs; bs_t bs;
} out; } out;
uint64_t bytes_written; uint64_t bytes_written;
uint64_t packets_written; uint64_t packets_written;
int ts_type; int ts_type;
int ts_id; int ts_id;
int cbr; int cbr;
int ts_muxrate; int ts_muxrate;
int pat_cc; int pat_cc;
int num_programs; int num_programs;
ts_int_program_t *programs[MAX_PROGRAMS]; ts_int_program_t *programs[MAX_PROGRAMS];
int pat_period; int pat_period;
int pcr_period; int pcr_period;
int first_input; int first_input;
int pat_version; int pat_version;
int network_pid; int network_pid;
int network_id; int network_id;
int num_buffered_frames; int num_buffered_frames;
ts_int_pes_t **buffered_frames; ts_int_pes_t **buffered_frames;
int num_pcrs; int num_pcrs;
int pcr_list_alloced; int pcr_list_alloced;
int64_t *pcr_list; int64_t *pcr_list;
/* system control */ /* system control */
buffer_t tb; /* transport buffer */ buffer_t tb; /* transport buffer */
buffer_t main_b; /* main buffer */ buffer_t main_b; /* main buffer */
int rx_sys; /* flow from transport to main buffer */ int rx_sys; /* flow from transport to main buffer */
int r_sys; /* flow from main buffer to system decoder */ int r_sys; /* flow from main buffer to system decoder */
/* CableLabs */ /* CableLabs */
int legacy_constraints; int legacy_constraints;
/* DVB-specific */ /* DVB-specific */
ts_int_stream_t *nit; ts_int_stream_t *nit;
ts_int_stream_t *sdt; ts_int_stream_t *sdt;
ts_int_stream_t *eit; ts_int_stream_t *eit;
ts_int_stream_t *tdt; ts_int_stream_t *tdt;
ts_int_stream_t *sit; ts_int_stream_t *sit;
uint64_t last_pat; uint64_t last_pat;
uint64_t last_pmt; uint64_t last_pmt;
uint64_t last_nit; uint64_t last_nit;
uint64_t last_sdt; uint64_t last_sdt;
uint64_t last_eit; uint64_t last_eit;
uint64_t last_tdt; uint64_t last_tdt;
uint64_t last_sit; uint64_t last_sit;
ts_dtcp_t *dtcp_ctx; ts_dtcp_t *dtcp_ctx;
}; };
enum adaptation_field_control_e enum adaptation_field_control_e
{ {
PAYLOAD_ONLY = 1, PAYLOAD_ONLY = 1,
ADAPT_FIELD_ONLY = 2, ADAPT_FIELD_ONLY = 2,
ADAPT_FIELD_AND_PAYLOAD = 3, ADAPT_FIELD_AND_PAYLOAD = 3,
}; };
void write_bytes( bs_t *s, uint8_t *bytes, int length ); void write_bytes( bs_t *s, uint8_t *bytes, int length );
void write_packet_header( ts_writer_t *w, bs_t *s, int start, int pid, int adapt_field, int *cc ); void write_packet_header( ts_writer_t *w, bs_t *s, int start, int pid, int adapt_field, int *cc );
void write_registration_descriptor( bs_t *s, int descriptor_tag, int descriptor_length, char *format_id ); void write_registration_descriptor( bs_t *s, int descriptor_tag, int descriptor_length, char *format_id );
void write_crc( bs_t *s, int start ); void write_crc( bs_t *s, int start );
int write_padding( bs_t *s, int start ); int write_padding( bs_t *s, int start );
int increase_pcr( ts_writer_t *w, int num_packets, int imaginary ); int increase_pcr( ts_writer_t *w, int num_packets, int imaginary );
ts_int_stream_t *find_stream( ts_writer_t *w, int pid ); ts_int_stream_t *find_stream( ts_writer_t *w, int pid );
#endif #endif

780
dvb/dvb.c
Wyświetl plik

@ -1,390 +1,390 @@
/***************************************************************************** /*****************************************************************************
* dvb.c : DVB functions * dvb.c : DVB functions
***************************************************************************** *****************************************************************************
* Copyright (C) 2010 Kieran Kunhya * Copyright (C) 2010 Kieran Kunhya
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
*****************************************************************************/ *****************************************************************************/
#include <time.h> #include <time.h>
#include "../common.h" #include "../common.h"
#include "dvb.h" #include "dvb.h"
/**** PMT Second Loop Descriptors ****/ /**** PMT Second Loop Descriptors ****/
void write_aac_descriptor( bs_t *s, ts_int_stream_t *stream ) void write_aac_descriptor( bs_t *s, ts_int_stream_t *stream )
{ {
bs_write( s, 8, DVB_AAC_DESCRIPTOR_TAG ); // descriptor_tag bs_write( s, 8, DVB_AAC_DESCRIPTOR_TAG ); // descriptor_tag
bs_write( s, 8, 1 ); // descriptor_length bs_write( s, 8, 1 ); // descriptor_length
bs_write( s, 8, stream->aac_profile ); // profile_and_level bs_write( s, 8, stream->aac_profile ); // profile_and_level
} }
void write_adaptation_field_data_descriptor( bs_t *s, uint8_t identifier ) void write_adaptation_field_data_descriptor( bs_t *s, uint8_t identifier )
{ {
bs_write( s, 8, DVB_ADAPTATION_FIELD_DATA_DESCRIPTOR ); // descriptor_tag bs_write( s, 8, DVB_ADAPTATION_FIELD_DATA_DESCRIPTOR ); // descriptor_tag
bs_write( s, 8, 1 ); // descriptor_length bs_write( s, 8, 1 ); // descriptor_length
bs_write( s, 8, identifier ); // adaptation_field_data_identifier bs_write( s, 8, identifier ); // adaptation_field_data_identifier
} }
void write_dvb_subtitling_descriptor( bs_t *s, ts_int_stream_t *stream ) void write_dvb_subtitling_descriptor( bs_t *s, ts_int_stream_t *stream )
{ {
ts_dvb_sub_t *subtitle; ts_dvb_sub_t *subtitle;
bs_write( s, 8, DVB_SUBTITLING_DESCRIPTOR_TAG ); // descriptor_tag bs_write( s, 8, DVB_SUBTITLING_DESCRIPTOR_TAG ); // descriptor_tag
bs_write( s, 8, stream->num_dvb_sub * 8 ); // descriptor_length bs_write( s, 8, stream->num_dvb_sub * 8 ); // descriptor_length
for( int i = 0; i < stream->num_dvb_sub; i++ ) for( int i = 0; i < stream->num_dvb_sub; i++ )
{ {
subtitle = &stream->dvb_sub_ctx[i]; subtitle = &stream->dvb_sub_ctx[i];
for( int j = 0; j < 3; j++ ) for( int j = 0; j < 3; j++ )
bs_write( s, 8, subtitle->lang_code[j] ); // ISO_639_language_code bs_write( s, 8, subtitle->lang_code[j] ); // ISO_639_language_code
bs_write( s, 8, subtitle->subtitling_type ); // subtitling_type bs_write( s, 8, subtitle->subtitling_type ); // subtitling_type
bs_write( s, 16, subtitle->composition_page_id ); // composition_page_id bs_write( s, 16, subtitle->composition_page_id ); // composition_page_id
bs_write( s, 16, subtitle->ancillary_page_id ); // ancillary_page_id bs_write( s, 16, subtitle->ancillary_page_id ); // ancillary_page_id
} }
} }
void write_stream_identifier_descriptor( bs_t *s, uint8_t stream_identifier ) void write_stream_identifier_descriptor( bs_t *s, uint8_t stream_identifier )
{ {
bs_write( s, 8, DVB_STREAM_IDENTIFIER_DESCRIPTOR_TAG ); // descriptor_tag bs_write( s, 8, DVB_STREAM_IDENTIFIER_DESCRIPTOR_TAG ); // descriptor_tag
bs_write( s, 8, 1 ); // descriptor_length bs_write( s, 8, 1 ); // descriptor_length
bs_write( s, 8, stream_identifier ); // component_tag bs_write( s, 8, stream_identifier ); // component_tag
} }
void write_teletext_descriptor( bs_t *s, ts_int_stream_t *stream, int vbi ) void write_teletext_descriptor( bs_t *s, ts_int_stream_t *stream, int vbi )
{ {
ts_dvb_ttx_t *teletext; ts_dvb_ttx_t *teletext;
if( vbi ) if( vbi )
bs_write( s, 8, DVB_VBI_TELETEXT_DESCRIPTOR_TAG ); // descriptor_tag bs_write( s, 8, DVB_VBI_TELETEXT_DESCRIPTOR_TAG ); // descriptor_tag
else else
bs_write( s, 8, DVB_TELETEXT_DESCRIPTOR_TAG ); // descriptor_tag bs_write( s, 8, DVB_TELETEXT_DESCRIPTOR_TAG ); // descriptor_tag
bs_write( s, 8, stream->num_dvb_ttx * 5 ); // descriptor_length bs_write( s, 8, stream->num_dvb_ttx * 5 ); // descriptor_length
for( int i = 0; i < stream->num_dvb_ttx; i++ ) for( int i = 0; i < stream->num_dvb_ttx; i++ )
{ {
teletext = &stream->dvb_ttx_ctx[i]; teletext = &stream->dvb_ttx_ctx[i];
for( int j = 0; j < 3; j++ ) for( int j = 0; j < 3; j++ )
bs_write( s, 8, teletext->lang_code[j] ); // ISO_639_language_code bs_write( s, 8, teletext->lang_code[j] ); // ISO_639_language_code
bs_write( s, 5, teletext->teletext_type ); // teletext_type bs_write( s, 5, teletext->teletext_type ); // teletext_type
bs_write( s, 3, teletext->teletext_magazine_number ); // teletext_magazine_number bs_write( s, 3, teletext->teletext_magazine_number ); // teletext_magazine_number
bs_write( s, 8, teletext->teletext_page_number ); // teletext_page_number bs_write( s, 8, teletext->teletext_page_number ); // teletext_page_number
} }
} }
void write_vbi_descriptor( bs_t *s, ts_int_stream_t *stream ) void write_vbi_descriptor( bs_t *s, ts_int_stream_t *stream )
{ {
bs_t q; bs_t q;
uint8_t temp[1024]; uint8_t temp[1024];
ts_dvb_vbi_t *vbi; ts_dvb_vbi_t *vbi;
bs_init( &q, temp, 1024 ); bs_init( &q, temp, 1024 );
bs_write( s, 8, DVB_VBI_DESCRIPTOR_TAG ); // descriptor_tag bs_write( s, 8, DVB_VBI_DESCRIPTOR_TAG ); // descriptor_tag
for( int i = 0; i < stream->num_dvb_vbi; i++ ) for( int i = 0; i < stream->num_dvb_vbi; i++ )
{ {
vbi = &stream->dvb_vbi_ctx[i]; vbi = &stream->dvb_vbi_ctx[i];
bs_write( &q, 8, vbi->data_service_id ); // data_service_id bs_write( &q, 8, vbi->data_service_id ); // data_service_id
bs_write( &q, 8, vbi->num_lines ); // data_service_descriptor_length bs_write( &q, 8, vbi->num_lines ); // data_service_descriptor_length
for( int j = 0; j < vbi->num_lines; j++ ) for( int j = 0; j < vbi->num_lines; j++ )
{ {
bs_write( &q, 2, 0x3 ); // reserved bs_write( &q, 2, 0x3 ); // reserved
bs_write( &q, 1, vbi->lines[j].field_parity ); // field_parity bs_write( &q, 1, vbi->lines[j].field_parity ); // field_parity
bs_write( &q, 5, vbi->lines[j].line_offset ); // line_offset bs_write( &q, 5, vbi->lines[j].line_offset ); // line_offset
} }
} }
bs_flush( &q ); bs_flush( &q );
bs_write( s, 8, bs_pos( &q ) >> 3 ); // descriptor_length bs_write( s, 8, bs_pos( &q ) >> 3 ); // descriptor_length
write_bytes( s, temp, bs_pos( &q ) >> 3 ); write_bytes( s, temp, bs_pos( &q ) >> 3 );
} }
/* /*
static void write_service_descriptor( bs_t *s ) static void write_service_descriptor( bs_t *s )
{ {
bs_write( s, 8, DVB_SERVICE_DESCRIPTOR_TAG ); // descriptor_tag bs_write( s, 8, DVB_SERVICE_DESCRIPTOR_TAG ); // descriptor_tag
bs_write( s, 8, 0 ); // descriptor_length bs_write( s, 8, 0 ); // descriptor_length
bs_write( s, 8, 0 ); // service_type bs_write( s, 8, 0 ); // service_type
bs_write( s, 8, 0 ); // service_provider_name_length bs_write( s, 8, 0 ); // service_provider_name_length
// TODO support more character codes // TODO support more character codes
while( *provider_name != '\0' ) while( *provider_name != '\0' )
bs_write( s, 8, *provider_name++ ); bs_write( s, 8, *provider_name++ );
bs_write( s, 8, name_len ); // service_name_length bs_write( s, 8, name_len ); // service_name_length
while( *name != '\0' ) while( *name != '\0' )
bs_write( s, 8, *name++ ); bs_write( s, 8, *name++ );
} }
*/ */
/* DVB Service Information */ /* DVB Service Information */
int write_nit( ts_writer_t *w ) int write_nit( ts_writer_t *w )
{ {
int start; int start;
bs_t *s = &w->out.bs; bs_t *s = &w->out.bs;
write_packet_header( w, s, 1, w->network_pid, PAYLOAD_ONLY, &w->nit->cc ); write_packet_header( w, s, 1, w->network_pid, PAYLOAD_ONLY, &w->nit->cc );
bs_write( s, 8, 0 ); // pointer field bs_write( s, 8, 0 ); // pointer field
start = bs_pos( s ); start = bs_pos( s );
bs_write( s, 8, NIT_TID ); // table_id = network_information_section bs_write( s, 8, NIT_TID ); // table_id = network_information_section
bs_write1( s, 1 ); // section_syntax_indicator bs_write1( s, 1 ); // section_syntax_indicator
bs_write1( s, 1 ); // reserved_future_use bs_write1( s, 1 ); // reserved_future_use
bs_write( s, 2, 0x03 ); // reserved bs_write( s, 2, 0x03 ); // reserved
bs_write( s, 12, 0x13 ); // section_length bs_write( s, 12, 0x13 ); // section_length
bs_write( s, 16, w->network_id ); // network_id bs_write( s, 16, w->network_id ); // network_id
bs_write( s, 2, 0x02 ); // reserved bs_write( s, 2, 0x02 ); // reserved
bs_write( s, 5, 0 ); // version_number bs_write( s, 5, 0 ); // version_number
bs_write1( s, 1 ); // current_next_indicator bs_write1( s, 1 ); // current_next_indicator
bs_write(s, 8, 0 ); // section_number bs_write(s, 8, 0 ); // section_number
bs_write(s, 8, 0 ); // last_section_number bs_write(s, 8, 0 ); // last_section_number
bs_write(s, 4, 0xf ); // reserved_future_use bs_write(s, 4, 0xf ); // reserved_future_use
bs_write(s, 12, 0 ); // network_descriptors_length bs_write(s, 12, 0 ); // network_descriptors_length
// network descriptor(s) here // network descriptor(s) here
bs_write(s, 4, 0xf ); // reserved_future_use bs_write(s, 4, 0xf ); // reserved_future_use
bs_write(s, 12, 0 ); // transport_stream_loop_length bs_write(s, 12, 0 ); // transport_stream_loop_length
bs_write( s, 16, w->ts_id ); // transport_stream_id bs_write( s, 16, w->ts_id ); // transport_stream_id
bs_write( s, 16, w->network_id ); // original_network_id bs_write( s, 16, w->network_id ); // original_network_id
bs_write( s, 4, 0xf ); // reserved_future_use bs_write( s, 4, 0xf ); // reserved_future_use
bs_write(s, 12, 0 ); // transport_descriptors_length bs_write(s, 12, 0 ); // transport_descriptors_length
// transport descriptor(s) here // transport descriptor(s) here
bs_flush( s ); bs_flush( s );
write_crc( s, start ); write_crc( s, start );
// -40 to include header and pointer field // -40 to include header and pointer field
write_padding( s, start - 40 ); write_padding( s, start - 40 );
if( increase_pcr( w, 1, 0 ) < 0 ) if( increase_pcr( w, 1, 0 ) < 0 )
return -1; return -1;
return 0; return 0;
} }
#if 0 #if 0
/* "The SDT contains data describing the services in the system e.g. names of services, the service provider, etc" */ /* "The SDT contains data describing the services in the system e.g. names of services, the service provider, etc" */
void write_sdt( ts_writer_t *w ) void write_sdt( ts_writer_t *w )
{ {
uint64_t start; uint64_t start;
int i; int i;
bs_t *s = &w->out.bs; bs_t *s = &w->out.bs;
write_packet_header( w, s, 1, SDT_PID, PAYLOAD_ONLY, &w->sdt->cc ); write_packet_header( w, s, 1, SDT_PID, PAYLOAD_ONLY, &w->sdt->cc );
bs_write( s, 8, 0 ); // pointer field bs_write( s, 8, 0 ); // pointer field
start = bs_pos( s ); start = bs_pos( s );
bs_write( s, 8, SDT_TID ); // table_id bs_write( s, 8, SDT_TID ); // table_id
bs_write1( s, 1 ); // section_syntax_indicator bs_write1( s, 1 ); // section_syntax_indicator
bs_write1( s, 1 ); // reserved_future_use bs_write1( s, 1 ); // reserved_future_use
bs_write1( s, 1 ); // reserved bs_write1( s, 1 ); // reserved
// TODO temp // TODO temp
bs_write( s, 12, len ); // section_length bs_write( s, 12, len ); // section_length
bs_write( s, 16, w->ts_id ); // transport_stream_id bs_write( s, 16, w->ts_id ); // transport_stream_id
bs_write( s, 2, 0x03 ); // reserved bs_write( s, 2, 0x03 ); // reserved
bs_write( s, 5, 0 ); // version_number bs_write( s, 5, 0 ); // version_number
bs_write1( s, 1 ); // current_next_indicator bs_write1( s, 1 ); // current_next_indicator
bs_write( s, 8, 0 ); // section_number bs_write( s, 8, 0 ); // section_number
bs_write( s, 8, 0 ); // last_section_number bs_write( s, 8, 0 ); // last_section_number
bs_write( s, 8, w->nid ); // original_network_id bs_write( s, 8, w->nid ); // original_network_id
bs_write( s, 8, 0xff ); // reserved_future_use bs_write( s, 8, 0xff ); // reserved_future_use
for( i = 0; i < w->num_programs; i++ ) for( i = 0; i < w->num_programs; i++ )
{ {
bs_write( s, 16, w->programs[i]->program_num & 0xffff ); // service_id (equivalent to program_number) bs_write( s, 16, w->programs[i]->program_num & 0xffff ); // service_id (equivalent to program_number)
bs_write( s, 6, 0x7f ); // reserved_future_use bs_write( s, 6, 0x7f ); // reserved_future_use
bs_write1( s, 0 ); // EIT_schedule_flag bs_write1( s, 0 ); // EIT_schedule_flag
bs_write1( s, 1 ); // EIT_present_following_flag bs_write1( s, 1 ); // EIT_present_following_flag
bs_write( s, 3, 0 ); // running_status bs_write( s, 3, 0 ); // running_status
bs_write1( s, 1 ); // free_CA_mode bs_write1( s, 1 ); // free_CA_mode
int provider_name_len = strlen( w->programs[i]->sdt_ctx->provider_name ); int provider_name_len = strlen( w->programs[i]->sdt_ctx->provider_name );
int name_len = strlen( w->programs[i]->sdt_ctx->service_name ); int name_len = strlen( w->programs[i]->sdt_ctx->service_name );
char *provider_name = w->programs[i]->sdt_ctx->provider_name; char *provider_name = w->programs[i]->sdt_ctx->provider_name;
char *name = w->programs[i]->sdt_ctx->service_name; char *name = w->programs[i]->sdt_ctx->service_name;
int descriptors_len = 5 + provider_name_len + name_len; int descriptors_len = 5 + provider_name_len + name_len;
bs_write( s, 12, descriptors_len ); // descriptors_loop_length bs_write( s, 12, descriptors_len ); // descriptors_loop_length
// service descriptor (mandatory for DVB) // service descriptor (mandatory for DVB)
// other descriptor(s) here // other descriptor(s) here
} }
bs_flush( s ); bs_flush( s );
write_crc( s, start ); write_crc( s, start );
// -40 to include header and pointer field // -40 to include header and pointer field
write_padding( s, start - 40 ); write_padding( s, start - 40 );
increase_pcr( w, 1 ); increase_pcr( w, 1 );
} }
#endif #endif
#if 0 #if 0
// FIXME // FIXME
// "the EIT contains data concerning events or programmes such as event name, start time, duration, etc.; " // "the EIT contains data concerning events or programmes such as event name, start time, duration, etc.; "
void write_eit( ts_writer_t *w ) void write_eit( ts_writer_t *w )
{ {
uint64_t start; uint64_t start;
bs_t *s = &w->out.bs; bs_t *s = &w->out.bs;
write_packet_header( w, s, 1, EIT_PID, PAYLOAD_ONLY, &w->eit->cc ); write_packet_header( w, s, 1, EIT_PID, PAYLOAD_ONLY, &w->eit->cc );
bs_write( s, 8, 0 ); // pointer field bs_write( s, 8, 0 ); // pointer field
start = bs_pos( s ); start = bs_pos( s );
bs_write( s, 8, EIT_TID ); // table_id bs_write( s, 8, EIT_TID ); // table_id
bs_write1( s, 0 ); // section_syntax_indicator CHECKME bs_write1( s, 0 ); // section_syntax_indicator CHECKME
bs_write1( s, 1 ); // reserved_future_use bs_write1( s, 1 ); // reserved_future_use
bs_write( s, 2, 0x03); // reserved bs_write( s, 2, 0x03); // reserved
bs_write( s, 12, len ); // section_length bs_write( s, 12, len ); // section_length
} }
#endif #endif
static void write_utc_time( bs_t *s ) static void write_utc_time( bs_t *s )
{ {
int l, mjd; int l, mjd;
time_t cur_time; time_t cur_time;
struct tm *now; struct tm *now;
/* MJD conversions in Annex C of ETSI EN 300 468 */ /* MJD conversions in Annex C of ETSI EN 300 468 */
cur_time = time( NULL ); cur_time = time( NULL );
now = gmtime( &cur_time ); now = gmtime( &cur_time );
l = ( ( now->tm_mon + 1 == 1 ) || ( now->tm_mon + 1 == 2 ) ) ? 1 : 0; l = ( ( now->tm_mon + 1 == 1 ) || ( now->tm_mon + 1 == 2 ) ) ? 1 : 0;
mjd = 14956 + now->tm_mday + (int)((now->tm_year - l) * 365.25) + (int)((now->tm_mon + 1 + 1 + l * 12) * 30.6001); mjd = 14956 + now->tm_mday + (int)((now->tm_year - l) * 365.25) + (int)((now->tm_mon + 1 + 1 + l * 12) * 30.6001);
bs_write( s, 8, mjd >> 8 ); bs_write( s, 8, mjd >> 8 );
bs_write( s, 8, mjd & 0xff ); bs_write( s, 8, mjd & 0xff );
bs_write( s, 8, (now->tm_hour / 10) << 4 | (now->tm_hour % 10) ); // hours bs_write( s, 8, (now->tm_hour / 10) << 4 | (now->tm_hour % 10) ); // hours
bs_write( s, 8, (now->tm_min / 10) << 4 | (now->tm_min % 10) ); // minutes bs_write( s, 8, (now->tm_min / 10) << 4 | (now->tm_min % 10) ); // minutes
bs_write( s, 8, (now->tm_sec / 10) << 4 | (now->tm_sec % 10) ); // seconds bs_write( s, 8, (now->tm_sec / 10) << 4 | (now->tm_sec % 10) ); // seconds
} }
int write_tdt( ts_writer_t *w ) int write_tdt( ts_writer_t *w )
{ {
int start; int start;
bs_t *s = &w->out.bs; bs_t *s = &w->out.bs;
write_packet_header( w, s, 1, TDT_PID, PAYLOAD_ONLY, &w->tdt->cc ); write_packet_header( w, s, 1, TDT_PID, PAYLOAD_ONLY, &w->tdt->cc );
bs_write( s, 8, 0 ); // pointer field bs_write( s, 8, 0 ); // pointer field
start = bs_pos( s ); start = bs_pos( s );
bs_write( s, 8, TDT_TID ); // table_id bs_write( s, 8, TDT_TID ); // table_id
bs_write1( s, 0 ); // section_syntax_indicator bs_write1( s, 0 ); // section_syntax_indicator
bs_write1( s, 1 ); // reserved_future_use bs_write1( s, 1 ); // reserved_future_use
bs_write( s, 2, 0x03 ); // reserved bs_write( s, 2, 0x03 ); // reserved
bs_write( s, 12, 0x05 ); // section_length bs_write( s, 12, 0x05 ); // section_length
write_utc_time( s ); write_utc_time( s );
// -40 to include header and pointer field // -40 to include header and pointer field
write_padding( s, start - 40 ); write_padding( s, start - 40 );
if( increase_pcr( w, 1, 0 ) < 0 ) if( increase_pcr( w, 1, 0 ) < 0 )
return -1; return -1;
return 0; return 0;
} }
// TODO TOT // TODO TOT
void write_dvb_au_information( bs_t *s, ts_int_pes_t *pes ) void write_dvb_au_information( bs_t *s, ts_int_pes_t *pes )
{ {
bs_t q; bs_t q;
uint8_t temp[128]; uint8_t temp[128];
ts_int_stream_t *stream = pes->stream; ts_int_stream_t *stream = pes->stream;
bs_write( s, 8, AU_INFORMATION_DATA_FIELD ); // data_field_tag bs_write( s, 8, AU_INFORMATION_DATA_FIELD ); // data_field_tag
bs_init( &q, temp, 128 ); bs_init( &q, temp, 128 );
if( stream->stream_format == LIBMPEGTS_VIDEO_MPEG2 ) if( stream->stream_format == LIBMPEGTS_VIDEO_MPEG2 )
bs_write( &q, 4, 1 ); // AU_coding_format bs_write( &q, 4, 1 ); // AU_coding_format
else if( stream->stream_format == LIBMPEGTS_VIDEO_AVC ) else if( stream->stream_format == LIBMPEGTS_VIDEO_AVC )
bs_write( &q, 4, 0x2 ); // AU_coding_format bs_write( &q, 4, 0x2 ); // AU_coding_format
bs_write( &q, 4, pes->frame_type ); // AU_coding_type_information bs_write( &q, 4, pes->frame_type ); // AU_coding_type_information
bs_write( &q, 2, pes->ref_pic_idc ); // AU_ref_pic_idc bs_write( &q, 2, pes->ref_pic_idc ); // AU_ref_pic_idc
if( stream->stream_format == LIBMPEGTS_VIDEO_MPEG2 ) if( stream->stream_format == LIBMPEGTS_VIDEO_MPEG2 )
bs_write( &q, 2, pes->pic_struct ); // AU_pic_struct bs_write( &q, 2, pes->pic_struct ); // AU_pic_struct
else if( stream->stream_format == LIBMPEGTS_VIDEO_AVC ) else if( stream->stream_format == LIBMPEGTS_VIDEO_AVC )
bs_write( &q, 2, 0 ); // AU_coding_format bs_write( &q, 2, 0 ); // AU_coding_format
bs_write1( &q, 1 ); // AU_PTS_present_flag bs_write1( &q, 1 ); // AU_PTS_present_flag
bs_write1( &q, 1 ); // AU_profile_info_present_flag bs_write1( &q, 1 ); // AU_profile_info_present_flag
bs_write1( &q, 1 ); // AU_stream_info_present_flag bs_write1( &q, 1 ); // AU_stream_info_present_flag
bs_write1( &q, 0 ); // AU_trick_mode_info_present_flag bs_write1( &q, 0 ); // AU_trick_mode_info_present_flag
bs_write32( &q, (pes->pts * 300) & 0xffffffff ); // AU_PTS_32 bs_write32( &q, (pes->pts * 300) & 0xffffffff ); // AU_PTS_32
bs_write( &q, 4, 0 ); // reserved bs_write( &q, 4, 0 ); // reserved
bs_write( &q, 4, stream->dvb_au_frame_rate ); // AU_frame_rate_code bs_write( &q, 4, stream->dvb_au_frame_rate ); // AU_frame_rate_code
bs_write( &q, 8, stream->mpegvideo_ctx->profile & 0xff ); // profile_idc bs_write( &q, 8, stream->mpegvideo_ctx->profile & 0xff ); // profile_idc
if( stream->stream_format == LIBMPEGTS_VIDEO_AVC ) if( stream->stream_format == LIBMPEGTS_VIDEO_AVC )
{ {
bs_write1( &q, stream->mpegvideo_ctx->profile == AVC_BASELINE ); // constraint_set0_flag bs_write1( &q, stream->mpegvideo_ctx->profile == AVC_BASELINE ); // constraint_set0_flag
bs_write1( &q, stream->mpegvideo_ctx->profile <= AVC_MAIN ); // constraint_set1_flag bs_write1( &q, stream->mpegvideo_ctx->profile <= AVC_MAIN ); // constraint_set1_flag
bs_write1( &q, 0 ); // constraint_set2_flag bs_write1( &q, 0 ); // constraint_set2_flag
if( stream->mpegvideo_ctx->level == 9 && stream->mpegvideo_ctx->profile <= AVC_MAIN ) // level 1b if( stream->mpegvideo_ctx->level == 9 && stream->mpegvideo_ctx->profile <= AVC_MAIN ) // level 1b
bs_write1( &q, 1 ); // constraint_set3_flag bs_write1( &q, 1 ); // constraint_set3_flag
else if( stream->mpegvideo_ctx->profile == AVC_HIGH_10_INTRA || else if( stream->mpegvideo_ctx->profile == AVC_HIGH_10_INTRA ||
stream->mpegvideo_ctx->profile == AVC_CAVLC_444_INTRA || stream->mpegvideo_ctx->profile == AVC_CAVLC_444_INTRA ||
stream->mpegvideo_ctx->profile == AVC_HIGH_444_INTRA ) stream->mpegvideo_ctx->profile == AVC_HIGH_444_INTRA )
bs_write1( &q, 1 ); // constraint_set3_flag bs_write1( &q, 1 ); // constraint_set3_flag
else else
bs_write1( &q, 0 ); // constraint_set3_flag bs_write1( &q, 0 ); // constraint_set3_flag
bs_write1( &q, 0 ); // constraint_set4_flag bs_write1( &q, 0 ); // constraint_set4_flag
bs_write1( &q, 0 ); // constraint_set5_flag bs_write1( &q, 0 ); // constraint_set5_flag
} }
else else
bs_write( &q, 5, 0 ); bs_write( &q, 5, 0 );
bs_write( &q, 2, 0 ); // AU_AVC_compatible_flags bs_write( &q, 2, 0 ); // AU_AVC_compatible_flags
bs_write( &q, 8, stream->mpegvideo_ctx->level & 0xff ); // level_idc bs_write( &q, 8, stream->mpegvideo_ctx->level & 0xff ); // level_idc
if( pes->write_pulldown_info ) if( pes->write_pulldown_info )
{ {
bs_write1( &q, 1 ); // AU_Pulldown_info_present_flag bs_write1( &q, 1 ); // AU_Pulldown_info_present_flag
bs_write( &q, 6, 0 ); // AU_reserved_zero bs_write( &q, 6, 0 ); // AU_reserved_zero
bs_write1( &q, 0 ); // AU_flags_extension_1 bs_write1( &q, 0 ); // AU_flags_extension_1
bs_write( &q, 4, 0 ); // AU_reserved_zero bs_write( &q, 4, 0 ); // AU_reserved_zero
bs_write( &q, 4, pes->pic_struct & 0xf ); // AU_Pulldown_info bs_write( &q, 4, pes->pic_struct & 0xf ); // AU_Pulldown_info
} }
/* reserved bytes */ /* reserved bytes */
bs_flush( &q ); bs_flush( &q );
bs_write( s, 8, bs_pos( &q ) >> 3 ); // data_field_length bs_write( s, 8, bs_pos( &q ) >> 3 ); // data_field_length
write_bytes( s, temp, bs_pos( &q ) >> 3 ); write_bytes( s, temp, bs_pos( &q ) >> 3 );
} }

140
dvb/dvb.h
Wyświetl plik

@ -1,70 +1,70 @@
/***************************************************************************** /*****************************************************************************
* dvb.h : DVB specific headers * dvb.h : DVB specific headers
***************************************************************************** *****************************************************************************
* Copyright (C) 2010 Kieran Kunhya * Copyright (C) 2010 Kieran Kunhya
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
*****************************************************************************/ *****************************************************************************/
#ifndef LIBMPEGTS_DVB_H #ifndef LIBMPEGTS_DVB_H
#define LIBMPEGTS_DVB_H #define LIBMPEGTS_DVB_H
/* Descriptor Tags */ /* Descriptor Tags */
#define DVB_VBI_DESCRIPTOR_TAG 0x45 #define DVB_VBI_DESCRIPTOR_TAG 0x45
#define DVB_VBI_TELETEXT_DESCRIPTOR_TAG 0x46 #define DVB_VBI_TELETEXT_DESCRIPTOR_TAG 0x46
#define DVB_SERVICE_DESCRIPTOR_TAG 0x48 #define DVB_SERVICE_DESCRIPTOR_TAG 0x48
#define DVB_STREAM_IDENTIFIER_DESCRIPTOR_TAG 0x52 #define DVB_STREAM_IDENTIFIER_DESCRIPTOR_TAG 0x52
#define DVB_TELETEXT_DESCRIPTOR_TAG 0x56 #define DVB_TELETEXT_DESCRIPTOR_TAG 0x56
#define DVB_SUBTITLING_DESCRIPTOR_TAG 0x59 #define DVB_SUBTITLING_DESCRIPTOR_TAG 0x59
#define DVB_AC3_DESCRIPTOR_TAG 0x6a #define DVB_AC3_DESCRIPTOR_TAG 0x6a
#define DVB_ADAPTATION_FIELD_DATA_DESCRIPTOR 0x70 #define DVB_ADAPTATION_FIELD_DATA_DESCRIPTOR 0x70
#define DVB_EAC3_DESCRIPTOR_TAG 0x7a #define DVB_EAC3_DESCRIPTOR_TAG 0x7a
#define DVB_AAC_DESCRIPTOR_TAG 0x7c #define DVB_AAC_DESCRIPTOR_TAG 0x7c
/* PIDs */ /* PIDs */
#define SDT_PID 0x0011 #define SDT_PID 0x0011
#define EIT_PID 0x0012 #define EIT_PID 0x0012
#define TDT_PID 0x0014 #define TDT_PID 0x0014
/* TIDs */ /* TIDs */
#define SDT_TID 0x42 #define SDT_TID 0x42
#define EIT_TID 0x4e #define EIT_TID 0x4e
#define TDT_TID 0x70 #define TDT_TID 0x70
/* Default Retransmit times (ms) */ /* Default Retransmit times (ms) */
#define EIT_MAX_RETRANS_TIME 2000 #define EIT_MAX_RETRANS_TIME 2000
#define EIT_OTHER_TS_MAX_RETRANS_TIME 10000 #define EIT_OTHER_TS_MAX_RETRANS_TIME 10000
#define TDT_MAX_RETRANS_TIME 25000 #define TDT_MAX_RETRANS_TIME 25000
#define TOT_MAX_RETRANS_TIME 25000 #define TOT_MAX_RETRANS_TIME 25000
/* Private Data Bytes data_field_tags */ /* Private Data Bytes data_field_tags */
#define ANNOUNCEMENT_SWITCHING_DATA_FIELD 0x01 #define ANNOUNCEMENT_SWITCHING_DATA_FIELD 0x01
#define AU_INFORMATION_DATA_FIELD 0x02 #define AU_INFORMATION_DATA_FIELD 0x02
#define PVR_ASSIST_INFORMATION_DATA_FIELD 0x03 #define PVR_ASSIST_INFORMATION_DATA_FIELD 0x03
void write_aac_descriptor( bs_t *s, ts_int_stream_t *stream ); void write_aac_descriptor( bs_t *s, ts_int_stream_t *stream );
void write_adaptation_field_data_descriptor( bs_t *s, uint8_t identifier ); void write_adaptation_field_data_descriptor( bs_t *s, uint8_t identifier );
void write_dvb_subtitling_descriptor( bs_t *s, ts_int_stream_t *stream ); void write_dvb_subtitling_descriptor( bs_t *s, ts_int_stream_t *stream );
void write_stream_identifier_descriptor( bs_t *s, uint8_t stream_identifier ); void write_stream_identifier_descriptor( bs_t *s, uint8_t stream_identifier );
void write_teletext_descriptor( bs_t *s, ts_int_stream_t *stream, int vbi ); void write_teletext_descriptor( bs_t *s, ts_int_stream_t *stream, int vbi );
void write_vbi_descriptor( bs_t *s, ts_int_stream_t *stream ); void write_vbi_descriptor( bs_t *s, ts_int_stream_t *stream );
int write_nit( ts_writer_t *w ); int write_nit( ts_writer_t *w );
//void write_sdt( ts_writer_t *w ); //void write_sdt( ts_writer_t *w );
//void write_eit( ts_writer_t *w ); //void write_eit( ts_writer_t *w );
int write_tdt( ts_writer_t *w ); int write_tdt( ts_writer_t *w );
void write_dvb_au_information( bs_t *s, ts_int_pes_t *pes ); void write_dvb_au_information( bs_t *s, ts_int_pes_t *pes );
#endif #endif

Wyświetl plik

@ -1,127 +1,127 @@
/***************************************************************************** /*****************************************************************************
* hdmv.c : HDMV specific functions * hdmv.c : HDMV specific functions
***************************************************************************** *****************************************************************************
* Copyright (C) 2010 Kieran Kunhya * Copyright (C) 2010 Kieran Kunhya
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
*****************************************************************************/ *****************************************************************************/
#include "../common.h" #include "../common.h"
#include "hdmv.h" #include "hdmv.h"
int ts_setup_hdmv_lpcm_stream( ts_writer_t *w, int pid, int num_channels, int sample_rate, int bits_per_sample ) int ts_setup_hdmv_lpcm_stream( ts_writer_t *w, int pid, int num_channels, int sample_rate, int bits_per_sample )
{ {
ts_int_stream_t *stream = find_stream( w, pid ); ts_int_stream_t *stream = find_stream( w, pid );
if( !stream ) if( !stream )
{ {
fprintf( stderr, "Invalid PID\n" ); fprintf( stderr, "Invalid PID\n" );
return -1; return -1;
} }
stream->lpcm_ctx = calloc( 1, sizeof(stream->lpcm_ctx) ); stream->lpcm_ctx = calloc( 1, sizeof(stream->lpcm_ctx) );
if( !stream->lpcm_ctx ) if( !stream->lpcm_ctx )
return -1; return -1;
stream->lpcm_ctx->num_channels = num_channels; stream->lpcm_ctx->num_channels = num_channels;
stream->lpcm_ctx->sample_rate = sample_rate; stream->lpcm_ctx->sample_rate = sample_rate;
stream->lpcm_ctx->bits_per_sample = bits_per_sample; stream->lpcm_ctx->bits_per_sample = bits_per_sample;
return 0; return 0;
} }
int ts_setup_dtcp( ts_writer_t *w, uint8_t byte_1, uint8_t byte_2 ) int ts_setup_dtcp( ts_writer_t *w, uint8_t byte_1, uint8_t byte_2 )
{ {
w->dtcp_ctx = calloc( 1, sizeof(w->dtcp_ctx) ); w->dtcp_ctx = calloc( 1, sizeof(w->dtcp_ctx) );
if( !w->dtcp_ctx ) if( !w->dtcp_ctx )
return -1; return -1;
w->dtcp_ctx->byte_1 = byte_1; w->dtcp_ctx->byte_1 = byte_1;
w->dtcp_ctx->byte_2 = byte_2; w->dtcp_ctx->byte_2 = byte_2;
return 0; return 0;
} }
/**** First Loop of PMT Descriptors ****/ /**** First Loop of PMT Descriptors ****/
void write_hdmv_copy_control_descriptor( ts_writer_t *w, bs_t *s ) void write_hdmv_copy_control_descriptor( ts_writer_t *w, bs_t *s )
{ {
bs_write( s, 8, HDMV_COPY_CTRL_DESCRIPTOR_TAG ); // descriptor_tag bs_write( s, 8, HDMV_COPY_CTRL_DESCRIPTOR_TAG ); // descriptor_tag
bs_write( s, 8, 0x04 ); // descriptor_length bs_write( s, 8, 0x04 ); // descriptor_length
bs_write( s, 16, 0x0fff ); // CA_System_ID bs_write( s, 16, 0x0fff ); // CA_System_ID
bs_write( s, 8, w->dtcp_ctx->byte_1 ); // private_data_byte bs_write( s, 8, w->dtcp_ctx->byte_1 ); // private_data_byte
bs_write( s, 8, w->dtcp_ctx->byte_2 ); // private_data_byte bs_write( s, 8, w->dtcp_ctx->byte_2 ); // private_data_byte
} }
/**** Second Loop of PMT Descriptors ****/ /**** Second Loop of PMT Descriptors ****/
void write_hdmv_video_registration_descriptor( bs_t *s, ts_int_stream_t *stream ) void write_hdmv_video_registration_descriptor( bs_t *s, ts_int_stream_t *stream )
{ {
char *format_id = "HDMV"; char *format_id = "HDMV";
bs_write( s, 8, REGISTRATION_DESCRIPTOR_TAG ); // descriptor_tag bs_write( s, 8, REGISTRATION_DESCRIPTOR_TAG ); // descriptor_tag
bs_write( s, 8, 0x8 ); // descriptor_length bs_write( s, 8, 0x8 ); // descriptor_length
while( *format_id != '\0' ) while( *format_id != '\0' )
bs_write( s, 8, *format_id++ ); // format_identifier bs_write( s, 8, *format_id++ ); // format_identifier
bs_write( s, 8, 0xff ); // stuffing_bits bs_write( s, 8, 0xff ); // stuffing_bits
bs_write( s, 8, stream->stream_id ); // stream_coding_type bs_write( s, 8, stream->stream_id ); // stream_coding_type
bs_write( s, 4, stream->hdmv_video_format ); // video_format bs_write( s, 4, stream->hdmv_video_format ); // video_format
bs_write( s, 4, stream->hdmv_frame_rate ); // frame_rate bs_write( s, 4, stream->hdmv_frame_rate ); // frame_rate
bs_write( s, 4, stream->hdmv_aspect_ratio ); // aspect_ratio bs_write( s, 4, stream->hdmv_aspect_ratio ); // aspect_ratio
bs_write( s, 4, 0xf ); // stuffing_bits bs_write( s, 4, 0xf ); // stuffing_bits
} }
void write_hdmv_lpcm_descriptor( bs_t *s, ts_int_stream_t *stream ) void write_hdmv_lpcm_descriptor( bs_t *s, ts_int_stream_t *stream )
{ {
write_registration_descriptor( s, REGISTRATION_DESCRIPTOR_TAG, 8, "HDMV" ); write_registration_descriptor( s, REGISTRATION_DESCRIPTOR_TAG, 8, "HDMV" );
bs_write( s, 8, 0xff ); // stuffing_bits bs_write( s, 8, 0xff ); // stuffing_bits
bs_write( s, 8, stream->stream_type ); // stream_coding_type bs_write( s, 8, stream->stream_type ); // stream_coding_type
if( stream->lpcm_ctx->num_channels == 1 ) if( stream->lpcm_ctx->num_channels == 1 )
bs_write( s, 4, 1 ); // audio_presentation_type bs_write( s, 4, 1 ); // audio_presentation_type
else if( stream->lpcm_ctx->num_channels == 2 ) else if( stream->lpcm_ctx->num_channels == 2 )
bs_write( s, 4, 0x03 ); // audio_presentation_type bs_write( s, 4, 0x03 ); // audio_presentation_type
else else
bs_write( s, 4, 0x06 ); // audio_presentation_type bs_write( s, 4, 0x06 ); // audio_presentation_type
if( stream->lpcm_ctx->sample_rate == 48 ) if( stream->lpcm_ctx->sample_rate == 48 )
bs_write( s, 4, 1 ); // sampling_frequency bs_write( s, 4, 1 ); // sampling_frequency
else if( stream->lpcm_ctx->sample_rate == 96 ) else if( stream->lpcm_ctx->sample_rate == 96 )
bs_write( s, 4, 0x04 ); // sampling_frequency bs_write( s, 4, 0x04 ); // sampling_frequency
else else
bs_write( s, 4, 0x05 ); // sampling_frequency bs_write( s, 4, 0x05 ); // sampling_frequency
if( stream->lpcm_ctx->bits_per_sample == 16 ) if( stream->lpcm_ctx->bits_per_sample == 16 )
bs_write( s, 2, 1 ); // bits_per_sample bs_write( s, 2, 1 ); // bits_per_sample
else if( stream->lpcm_ctx->bits_per_sample == 20 ) else if( stream->lpcm_ctx->bits_per_sample == 20 )
bs_write( s, 2, 0x02 ); // bits_per_sample bs_write( s, 2, 0x02 ); // bits_per_sample
else else
bs_write( s, 2, 0x03 ); // bits_per_sample bs_write( s, 2, 0x03 ); // bits_per_sample
bs_write( s, 6, 0x3f ); // stuffing_bits bs_write( s, 6, 0x3f ); // stuffing_bits
} }
/**** In loop of SIT ****/ /**** In loop of SIT ****/
void write_partial_ts_descriptor( ts_writer_t *w, bs_t *s ) void write_partial_ts_descriptor( ts_writer_t *w, bs_t *s )
{ {
bs_write( s, 8, HDMV_PARTIAL_TS_DESCRIPTOR_TAG ); // descriptor_tag bs_write( s, 8, HDMV_PARTIAL_TS_DESCRIPTOR_TAG ); // descriptor_tag
bs_write( s, 8, 0x08 ); // descriptor_length bs_write( s, 8, 0x08 ); // descriptor_length
bs_write( s, 2, 0x03 ); // DVB_reserved_future_use bs_write( s, 2, 0x03 ); // DVB_reserved_future_use
bs_write( s, 22, w->ts_muxrate / 400 ); // peak_rate bs_write( s, 22, w->ts_muxrate / 400 ); // peak_rate
bs_write( s, 2, 0x03 ); // DVB_reserved_future_use bs_write( s, 2, 0x03 ); // DVB_reserved_future_use
bs_write( s, 22, 0x3fffff ); // minimum_overall_smoothing_rate bs_write( s, 22, 0x3fffff ); // minimum_overall_smoothing_rate
bs_write( s, 2, 0x03 ); // DVB_reserved_future_use bs_write( s, 2, 0x03 ); // DVB_reserved_future_use
bs_write( s, 14, 0x3fff ); // maximum_overall_smoothing_buffer bs_write( s, 14, 0x3fff ); // maximum_overall_smoothing_buffer
} }

Wyświetl plik

@ -1,47 +1,47 @@
/***************************************************************************** /*****************************************************************************
* hdmv.h : HDMV specific headers * hdmv.h : HDMV specific headers
***************************************************************************** *****************************************************************************
* Copyright (C) 2010 Kieran Kunhya * Copyright (C) 2010 Kieran Kunhya
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
*****************************************************************************/ *****************************************************************************/
#ifndef LIBMPEGTS_HDMV_H #ifndef LIBMPEGTS_HDMV_H
#define LIBMPEGTS_HDMV_H #define LIBMPEGTS_HDMV_H
/* Blu-Ray specific stream types */ /* Blu-Ray specific stream types */
#define AUDIO_LPCM 0x80 #define AUDIO_LPCM 0x80
#define AUDIO_DTS 0x82 #define AUDIO_DTS 0x82
#define AUDIO_DOLBY_LOSSLESS 0x83 #define AUDIO_DOLBY_LOSSLESS 0x83
#define AUDIO_DTS_HD 0x85 #define AUDIO_DTS_HD 0x85
#define AUDIO_DTS_HD_XLL 0x86 #define AUDIO_DTS_HD_XLL 0x86
#define AUDIO_EAC3_SECONDARY 0xa1 #define AUDIO_EAC3_SECONDARY 0xa1
#define AUDIO_DTS_HD_SECONDARY 0xa2 #define AUDIO_DTS_HD_SECONDARY 0xa2
#define SUB_PRESENTATION_GRAPHICS 0x90 #define SUB_PRESENTATION_GRAPHICS 0x90
#define SUB_INTERACTIVE_GRAPHICS 0x91 #define SUB_INTERACTIVE_GRAPHICS 0x91
#define SUB_TEXT 0x92 #define SUB_TEXT 0x92
/* Descriptor Tags */ /* Descriptor Tags */
#define HDMV_PARTIAL_TS_DESCRIPTOR_TAG 0x63 #define HDMV_PARTIAL_TS_DESCRIPTOR_TAG 0x63
#define HDMV_AC3_DESCRIPTOR_TAG 0x81 #define HDMV_AC3_DESCRIPTOR_TAG 0x81
#define HDMV_CAPTION_DESCRIPTOR_TAG 0x86 #define HDMV_CAPTION_DESCRIPTOR_TAG 0x86
#define HDMV_COPY_CTRL_DESCRIPTOR_TAG 0x88 #define HDMV_COPY_CTRL_DESCRIPTOR_TAG 0x88
void write_hdmv_copy_control_descriptor( ts_writer_t *w, bs_t *s ); void write_hdmv_copy_control_descriptor( ts_writer_t *w, bs_t *s );
void write_hdmv_video_registration_descriptor( bs_t *s, ts_int_stream_t *stream ); void write_hdmv_video_registration_descriptor( bs_t *s, ts_int_stream_t *stream );
void write_hdmv_lpcm_descriptor( bs_t *s, ts_int_stream_t *stream ); void write_hdmv_lpcm_descriptor( bs_t *s, ts_int_stream_t *stream );
void write_partial_ts_descriptor( ts_writer_t *w, bs_t *s ); void write_partial_ts_descriptor( ts_writer_t *w, bs_t *s );
#endif #endif

Wyświetl plik

@ -1,24 +1,24 @@
/***************************************************************************** /*****************************************************************************
* isdb.h : ISDB specific headers * isdb.h : ISDB specific headers
***************************************************************************** *****************************************************************************
* Copyright (C) 2010 Kieran Kunhya * Copyright (C) 2010 Kieran Kunhya
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
*****************************************************************************/ *****************************************************************************/
#ifndef LIBMPEGTS_ISDB_H #ifndef LIBMPEGTS_ISDB_H
#define LIBMPEGTS_ISDB_H #define LIBMPEGTS_ISDB_H
#endif #endif

Wyświetl plik

@ -1,30 +1,30 @@
/***************************************************************************** /*****************************************************************************
* smpte.c : SMPTE specific functions * smpte.c : SMPTE specific functions
***************************************************************************** *****************************************************************************
* Copyright (C) 2010 Kieran Kunhya * Copyright (C) 2010 Kieran Kunhya
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
*****************************************************************************/ *****************************************************************************/
#include "../common.h" #include "../common.h"
#include "smpte.h" #include "smpte.h"
void write_anc_data_descriptor( bs_t *s ) void write_anc_data_descriptor( bs_t *s )
{ {
bs_write( s, 8, USER_DEFINED_DESCRIPTOR_TAG ); // descriptor_tag bs_write( s, 8, USER_DEFINED_DESCRIPTOR_TAG ); // descriptor_tag
bs_write( s, 8, 0 ); // descriptor_length bs_write( s, 8, 0 ); // descriptor_length
/* Optional descriptors here */ /* Optional descriptors here */
} }

Wyświetl plik

@ -1,26 +1,26 @@
/***************************************************************************** /*****************************************************************************
* smpte.h : SMPTE specific headers * smpte.h : SMPTE specific headers
***************************************************************************** *****************************************************************************
* Copyright (C) 2010 Kieran Kunhya * Copyright (C) 2010 Kieran Kunhya
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
*****************************************************************************/ *****************************************************************************/
#ifndef LIBMPEGTS_SMPTE_H #ifndef LIBMPEGTS_SMPTE_H
#define LIBMPEGTS_SMPTE_H #define LIBMPEGTS_SMPTE_H
void write_anc_data_descriptor( bs_t *s ); void write_anc_data_descriptor( bs_t *s );
#endif #endif