Mercurial > pt1.oyama
view src/tssplitter_lite.h @ 128:3a7d8d2f0585
modify configure for -lrt
author | Naoya OYAMA <naoya.oyama@gmail.com> |
---|---|
date | Tue, 05 Oct 2010 01:55:54 +0900 |
parents | 9c7bc6c0327e |
children | 20442921bff5 |
line wrap: on
line source
/* -*- tab-width: 4; indent-tabs-mode: t -*- */ /* vim: set ts=4 sts=4 sw=4 noexpandtab number : */ /* tssplitter_lite.h -- split TS stream program's header. Copyright 2009 querulous Copyright 2010 Naoya OYAMA <naoya.oyama@gmail.com> 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 the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef _TS_SPLITTER_LITE_H_ #define _TS_SPLITTER_LITE_H_ #define __STDC_FORMAT_MACROS #include <inttypes.h> #include <unistd.h> #include <limits.h> #define LENGTH_PACKET (188) #define MAX_PID (8192) #define MAX_SERVICES (50) #define LENGTH_CRC_DATA (176) #define false (0) #define true (1) #define TSS_SUCCESS (0) #define TSS_ERROR (-1) #define TSS_NULL (-2) #define LENGTH_PAT_HEADER (12) #define C_CHAR_COMMA ',' #define C_CHAR_DOT '.' #define LENGTH_TS_HEADER (4) #define LENGTH_PES_HEADER (9) #define LENGTH_PTS (5) /* ²þÄûÈǥǥ¸¥¿¥ëÊüÁ÷¶µ²Ê½ñ(¾å) P101 ɽ1 ARIB¤Ç¤ÎPSI/SI¤Î¼ïÎà¤è¤ê»²¾È */ #define PAT (0x0000) //#define PMT /* PAT¤Ë¤è¤ë´ÖÀÜ»ØÄê */ #define CAT (0x0001) #define NIT (0x0010) #define SDT (0x0011) #define BAT (0x0011) #define EIT (0x0012) /* 0x0026, 0x0027 */ #define RST (0x0013) #define TDT (0x0014) /* Ãϥǥ¸¤Ç¤Ï»ÈÍѤµ¤ì¤Ê¤¤ */ #define TOT (0x0014) #define LIT (0x0020) /* ¤Þ¤¿¤ÏPMT¤Ë¤è¤ë´ÖÀÜ»ØÄê */ #define ERT (0x0021) /* ¤Þ¤¿¤ÏPMT¤Ë¤è¤ë´ÖÀÜ»ØÄê */ //#define ITT /* PMT¤Ë¤è¤ë´ÖÀÜ»ØÄê */ #define PCAT (0x0022) #define BIT (0x0024) #define NBIT (0x0025) //#define ECM /* PMT¤Ë¤è¤ë´ÖÀÜ»ØÄê */ //#define EMM /* CAT¤Ë¤è¤ë´ÖÀÜ»ØÄê */ #define LDT (0x0025) #define DCT (0x0017) //#define DTL /* DCT¤Ë¤è¤ë´ÖÀÜ»ØÄê */ #define DIT (0x001e) #define SIT (0x001f) #define SDTT (0x0023) #define CDT (0x0029) //#define DSM-CC_Section /* PMT¤Ë¤è¤ë´ÖÀÜ»ØÄê */ /* ¥»¥¯¥·¥ç¥ó¥Ø¥Ã¥ÀĹ */ /* TS ¥Ñ¥±¥Ã¥È¤Ë³Æ¥»¥¯¥·¥ç¥ó¤òÀßÃÖ¤¹¤ëºÝ¡¢³ºÅöTS¥Ñ¥±¥Ã¥È¤Î»Ä¥µ¥¤¥º¤¬ * ¤¤¤¯¤Ä°Ê¾å¤¢¤ì¤Ð½ñ¤¹þ¤á¤ë¤«¤ÎȽÄê¤Ë»ÈÍѤ¹¤ë¡£ * ¥Ç¥³¡¼¥É¤Ë¤Ï¤¢¤Þ¤ê½ÅÍפǤÏ̵¤¤¤«¤â */ #define SECTION_LENGTH_PAT (8) #define SECTION_LENGTH_PMT (8) #define SECTION_LENGTH_CAT (8) #define SECTION_LENGTH_NIT (8) #define SECTION_LENGTH_BIT (8) #define SECTION_LENGTH_SDT (11) #define SECTION_LENGTH_EIT (14) /* H-EIT, M-EIT, L-EIT ¤ò¼¨¤¹ */ #define SECTION_LENGTH_SDTT (15) #define SECTION_LENGTH_CDT (13) #define SECTION_LENGTH_TOT (10) enum { PTS_FLAG = 0x80, DTS_FLAG = 0x40, ESCR_FLAG = 0x20, ES_RATE_FLAG = 0x10, DSM_TRICK_MODE_FLAG = 0x08, COPY_INFO_FLAG = 0x04, CRC_FLAG = 0x02, EXTENSION_FLAG = 0x01 }; enum { PES_PRIVATE_DATA_FLAG = 0x80, PACK_HEADER_FIELD_FLAG = 0x40, PROGRAM_PACKET_SEQUENCE_COUNTER = 0x20, PSTD_BUFFER_FLAG = 0x10, PES_EXTENSION_FLAG2 = 0x01 }; /* * PCR¤«¤éSTC¤òÀ¸À®¤¹¤ë½èÍýÊý¼°(°Æ) * 1. PCR¤òÆó¤Ä¼èÆÀ¤¹¤ë¤Þ¤Ç¥ë¡¼¥×(1.¢²4.¤Þ¤Ç¤Ï½é´ü½èÍý¤Ç¼Â»Ü¤¹¤ë¤³¤È) * 2. ¥ë¡¼¥×³«»Ï»þ¹ï(PCR)¤È¡¢¥ë¡¼¥×È´¤±¤¿»þ¹ï(PCR)¤Îº¹Ê¬¤ò¼è¤ë * 3. ¥ë¡¼¥×³«»Ï¡Á½ªÎ»¤Î´Ö¤Ë½èÍý¤·¤¿¥Ñ¥±¥Ã¥È¿ô¤ò¿ô¤¨¤ë * 4. (2.¤ÎPCR¤Î¿Ê¤ó¤À»þ´Ö/3.¤Î¥Ñ¥±¥Ã¥È¿ô)¡¡¤Î·×»»¤Ë¤è¤Ã¤Æ¡¢1¥Ñ¥±¥Ã¥È¤Ë¤è¤Ã¤Æ¿Ê¤àPCR¤òÁÛÄꤹ¤ë * 5. TS¼õ¿®»þ¤Ë¡¢1¤Ä¤Î¥Ñ¥±¥Ã¥È¤ò½èÍý¤¹¤ëÅÙ¤Ë4.¤ÎÁÛÄꤹ¤ë·Ð²á»þ¹ï¤òPCR¤Ë¤·¹þ¤ó¤ÇSTC¤È¤¹¤ë * 6. PCR¤ò¿·µ¬¤Ë¼èÆÀ¤·¤¿¤é¡¢STC¤òÊäÀµ(¤½¤Î¤Þ¤ÞÂåÆþ)¤¹¤ë */ #define MAX_VIDEO (16) #define MAX_AUDIO (32) typedef struct _program_t { int64_t stc; int64_t cue; /* Ï¿²è³«»Ï»þ¹ï */ int pmt_packet_id; /* ³ºÅöProgram(Service ID)¤ËÂбþ¤¹¤ëPMT */ int pmt_version; /* ³ºÅöProgram(Service ID)¤ËÂбþ¤¹¤ëPMT¤ÎVersion */ int pcr_packet_id; /* ³ºÅöProgram(Service ID)¤ÎPCR¤òÊÝ»ý¤¹¤ëPID */ int64_t pcr1; /* PCR1 */ int64_t pcr2; /* PCR2 */ int pcr_packet_nb; /* ľÁ°¤ÎPCR¤ò¼õ¿®¤·¤¿¤È¤¤Î¥Ñ¥±¥Ã¥È¿ô */ int packet_nb; /* ľÁ°¤ÎProgram¤Î½èÍý¤ò¼Â»Ü¤·¤¿¤È¤¤Î¥Ñ¥±¥Ã¥È¿ô */ int64_t pcr_incr; /* ³ºÅöProgram(Service ID)¤Ë±÷¤¤¤Æ¡¢1¤Ä¤ÎTS¥Ñ¥±¥Ã¥È¤ò½èÍý¤·¤¿»þ¤Ë·Ð²á¤¹¤ë(¤ÈÁÛÄꤹ¤ë»þ´Ö) */ int video_start; /* VODEO0¤òÃßÀѳ«»Ï¤·¤Æ¤¤¤ë¡© */ int64_t video_pts; /* ºÇ¸å¤Ë½èÍý¤·¤¿VODEO0¤ÎES¤ÎPTS */ int video_nb; /* PMT ¤Ë¸ºß¤¹¤ë¥Ó¥Ç¥ª¥¹¥È¥ê¡¼¥à¤Î¿ô */ int audio_nb; /* PMT ¤Ë¸ºß¤¹¤ë²»À¼¥¹¥È¥ê¡¼¥à¤Î¿ô */ int video[MAX_VIDEO]; /* PS½ÐÎϤ¹¤ë¾ì¹ç¤Ë»È¤¦¤«¤â */ int audio[MAX_AUDIO]; /* PS½ÐÎϤ¹¤ë¾ì¹ç¤Ë»È¤¦¤«¤â */ } program_t; /* * program_t ¤ò¥µ¡¼¥Ó¥¹IDʬ½àÈ÷¤·¤Æ¡¢»ÈÍѤ¹¤ë¥¤¥á¡¼¥¸¤Ç¤¤¤¿¤±¤É¡¢ * ¥µ¡¼¥Ó¥¹ID¤ÎºÇÂçÃͤÏ0xFFFF¤Ç¤¢¤ë¤Î¤Ç¡¢ÀÅŪ¤Ë³ÎÊݤ¹¤ë¤È stack ¤¬´Êñ¤Ë°î¤ë¤Î¤Ç¡¢ * ¼Â¹Ô»þ¤Ë malloc ¤È¤¹¤ë¤«¤Ê¤¡ * ËÜÅö¤ÏɬÍפʤÀ¤±alloc¤¹¤ë¤Î¤¬¹¥¤Þ¤·¤¤¤Î¤À¤±¤É¡Ä */ typedef struct _splitpesbuf_t { program_t *Program; int64_t pts; int64_t dts; int size; u_char buffer[128*1024]; } splitpesbuf_t; typedef struct _splitesbuf_t { program_t *Program; int64_t pts; int64_t dts; int started; /* ³ºÅöES¤¬ÃßÀѳ«»Ï¤·¤Æ¤¤¤ë¤« */ int random_access_indicator; /* TS ¤Î random_access_indicator */ int fd; /* ³ºÅöES¤Îfd */ int size; u_char buffer[3*1024*1024]; } splitesbuf_t; /* PCR ¶¦ÍÍѹ½Â¤ÂÎ */ typedef struct _pcr_t { int pid; int sid_nb; /* PCR¤ò»²¾È¤·¤Æ¤¤¤ëServiceID(ProgramID)¤Î¿ô */ int sid[MAX_SERVICES]; } pcr_t; /** * splitter¹½Â¤ÂÎ */ typedef struct splitter { char *filename; /* ¥Õ¥¡¥¤¥ë̾¤ò¾å°Ì¤«¤é¤â¤é¤Ã¤Æ¤¯¤ë¤¿¤á¤Î¥Ý¥¤¥ó¥¿ */ char *arg_cue; /* °ú¿ô¤Ç¼èÆÀ¤·¤Æ¤¤¿Ï¿²è³«»Ï»þ¹ï(HHMISS) */ int esout; /* ES½ÐÎϤ¹¤ë¡© */ unsigned char pids[MAX_PID]; unsigned char pmt_pids[MAX_PID]; uint8_t cat_pids[MAX_PID]; uint8_t pcr_pids[MAX_PID]; /* PCR¤ÏÊ£¿ôServiceID(ProgramID)¤Ç¶¦Í¤µ¤ì¤ë */ pcr_t pcr[MAX_SERVICES]; int pcr_nb; unsigned char* pat; char** sid_list; unsigned char pat_count; int pmt_retain; int pmt_counter; int avail_pmts[MAX_SERVICES]; int num_pmts; splitpesbuf_t *pesbuf[MAX_PID]; splitesbuf_t *esbuf[MAX_PID]; program_t *program; int pid_sid_table[MAX_PID]; /* pid to sid ¤ÎÊÑ´¹¤ò¹Ô¤¦¤¿¤á¤Î¥Æ¡¼¥Ö¥ë */ time_t time_cue; time_t time_tot; int tot_packet_nb; /* TOT¼õ¿®»þ¤Î¥Ñ¥±¥Ã¥È¼õ¿®¿ô */ } splitter; /* b25 decoder would hoard up large chank */ typedef struct _splitbuf_t { int size; u_char buffer[1024*1024]; } splitbuf_t; splitter* split_startup(char *sid, char *filename, char *cue_time); int split_select(splitter *sp, ARIB_STD_B25_BUFFER *sbuf); void split_shutdown(splitter *sp); int split_ts(splitter *splitter, ARIB_STD_B25_BUFFER *sbuf, splitbuf_t *dbuf); #endif