annotate src/tssplitter_lite.c @ 164:7d8a5bb874ad

EXPERIMENTAL: Change phisical channel by mq_recv(). KNOWN ISSUE: Cannnot split BS-TBS(BS1_1). enable compile recpt1ctl. SID can specified by recpt1ctl.
author Naoya OYAMA <naoya.oyama@gmail.com>
date Mon, 01 Oct 2012 21:52:05 +0900
parents 30e91361506a
children b21f1e823ec3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
1 /* -*- tab-width: 4; indent-tabs-mode: t -*- */
117
ac39bb18136e commit test.
naoyan@johnstown.minaminoshima.org
parents: 112
diff changeset
2 /* vim: set ts=4 sts=4 sw=4 noexpandtab number : */
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
3 /* tssplitter_lite.c -- split TS stream.
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
4
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
5 Copyright 2009 querulous
143
e72dd5e8d53f Number of samples per ADTS packet instead of 1000 and 1024.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 124
diff changeset
6 Copyright 2010-2012 Naoya OYAMA <naoya.oyama@gmail.com>
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
7
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
11 (at your option) any later version.
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
12
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
16 GNU General Public License for more details.
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
17
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
20
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
21 #include <stdlib.h>
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
22 #include <stdio.h>
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
23 #include <string.h>
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
24 #include <ctype.h>
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
25
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
26 #include <fcntl.h>
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
27 #include <sys/stat.h>
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
28 #include <math.h>
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
29 #include <time.h>
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
30 #include "decoder.h"
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
31 #include "recpt1.h"
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
32 #include "tssplitter_lite.h"
146
066f33b2213a EXPERIMENTAL: Select a particular program from multi-channel.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 143
diff changeset
33 #include "ushare.h"
066f33b2213a EXPERIMENTAL: Select a particular program from multi-channel.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 143
diff changeset
34 #include "metadata.h"
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
35
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
36 #ifndef AV_RB32
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
37 #define AV_RB32(x) ((((const uint8_t*)(x))[0] << 24) | \
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
38 (((const uint8_t*)(x))[1] << 16) | \
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
39 (((const uint8_t*)(x))[2] << 8) | \
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
40 ((const uint8_t*)(x))[3])
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
41 #endif
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
42
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
43 #ifndef AV_RB24
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
44 #define AV_RB24(x) ((((const uint8_t*)(x))[0] << 16) | \
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
45 (((const uint8_t*)(x))[1] << 8) | \
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
46 ((const uint8_t*)(x))[2])
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
47 #endif
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
48
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
49 #ifndef AV_RB16
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
50 #define AV_RB16(x) ((((const uint8_t*)(x))[0] << 8) | ((const uint8_t*)(x))[1])
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
51 #endif
121
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
52 #define MAX_SERVICE_ID ( 0xffff )
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
53 #define LIST_DECIMAL "0123456789"
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
54 #define TSS_STREAM_TYPE_AUDIO (1)
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
55 #define TSS_STREAM_TYPE_VIDEO (2)
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
56
146
066f33b2213a EXPERIMENTAL: Select a particular program from multi-channel.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 143
diff changeset
57 //global
066f33b2213a EXPERIMENTAL: Select a particular program from multi-channel.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 143
diff changeset
58 extern struct ushare_t *ut;
066f33b2213a EXPERIMENTAL: Select a particular program from multi-channel.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 143
diff changeset
59
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
60 /* prototypes */
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
61 static int ReadTs(splitter *sp, ARIB_STD_B25_BUFFER *sbuf);
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
62 static int AnalyzePat(splitter *sp, unsigned char *buf);
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
63 static int RecreatePat(splitter *sp, unsigned char *buf, int *pos);
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
64 static char** AnalyzeSid(char *sid);
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
65 static int AnalyzePmt(splitter *sp, const uint8_t *buf, int sid, const int size);
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
66 static int GetCrc32(unsigned char *data, int len);
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
67 static int GetPid(unsigned char *data);
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
68 static int parse_tot( const unsigned char* packet, time_t *t );
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
69 //void dump_packet( const uint8_t *packet );
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
70 static int parse_pcr(int64_t *ppcr_high, int *ppcr_low, const uint8_t *packet);
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
71 static int DemuxTs(const uint8_t *packet, splitter *sp, const int pid);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
72 //static int pes2es(splitpesbuf_t *pesbuf, splitesbuf_t *esbuf, const int pid, int random_access_indicator);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
73 static int pes2es(splitpesbuf_t *pesbuf, splitesbuf_t *esbuf, const int pid);
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
74 static int64_t get_pts(const uint8_t *p);
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
75 //void search_mpeg_system_header(const uint8_t *p);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
76 static int esbuf_write(splitesbuf_t *esbuf);
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
77 static int pesbuf_packet_start_code_prefix(splitpesbuf_t *pesbuf);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
78 static int pesbuf_empty(splitpesbuf_t *pesbuf);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
79 void pesbuf_clear(splitpesbuf_t *pesbuf);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
80 static int pesbuf_add(splitpesbuf_t *pesbuf, const uint8_t *data, int len);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
81 static int esbuf_empty(splitesbuf_t *esbuf);
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
82 void esbuf_clear(splitesbuf_t *esbuf, uint64_t pts, uint64_t dts);
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
83 static int esbuf_add(splitesbuf_t *esbuf, const uint8_t *data, int len);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
84 static int get_pmt_version(const uint8_t *p);
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
85 static int next_adts_start_code(splitesbuf_t *esbuf, int offset);
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
86 static int is_video_stream(const int pid, splitesbuf_t *esbuf);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
87 static int is_audio_stream(const int pid, splitesbuf_t *esbuf);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
88 static int AnalyzeAdifHeader(splitesbuf_t *esbuf);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
89 static int get_adif_id(uint8_t *p);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
90 static int get_adif_layer(uint8_t *p);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
91 static int get_adif_protection_absent(uint8_t *p);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
92 static int get_adif_profile(uint8_t *p);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
93 static int get_adif_sampling_frequency_index(uint8_t *p);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
94 static int get_adif_private_bit(uint8_t *p);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
95 static int get_adif_channel_configuration(uint8_t *p);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
96 static int get_adif_original_copy(uint8_t *p);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
97 static int get_adif_home(uint8_t *p);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
98 static int get_adif_copyright_idication_bit(uint8_t *p);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
99 static int get_adif_copyright_idication_start(uint8_t *p);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
100 static int get_adif_aac_frame_length(uint8_t *p);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
101 static int get_adts_buffer_fullness(uint8_t *p);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
102 static int get_adts_no_raw_data_blocks_in_frame(uint8_t *p);
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
103 //static int search_pmt_program(splitter *sp, int pid);
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
104 static int search_gop_start_code(splitesbuf_t *esbuf);
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
105 static int creat_es_file(splitter *sp, int sid, int pid, int av_flag);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
106 static time_t cue2time(char *yyyymmddhhmiss);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
107 static int search_pcr_pid(splitter *sp, int pid);
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
108
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
109 /**
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
110 * サービスID解析
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
111 */
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
112 static char** AnalyzeSid(
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
113 char* sid) // [in] サービスID(カンマ区切りテキスト)
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
114 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
115 int i = 0;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
116 char** sid_list = NULL;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
117 char* p;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
118 int CommaNum = 0;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
119
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
120 /* sid は次の形式の引数を許容する */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
121 /* 指定無し */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
122 /* SID[0] */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
123 /* SID[0],SID[1],...,SID[N-1],SID[N] */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
124
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
125 /*カンマの数を数える*/
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
126 p = sid;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
127 while(*p != '\0')
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
128 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
129 if( *p == C_CHAR_COMMA ){
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
130 CommaNum++;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
131 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
132 p++;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
133 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
134
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
135 /* sid_listの数はカンマの数+2(NULL止めするから) */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
136 sid_list = malloc(sizeof(char*)*(CommaNum+2));
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
137 if ( sid_list == NULL )
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
138 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
139 fprintf(stderr, "AnalyzeSid() malloc error.\n");
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
140 return NULL;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
141 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
142
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
143 /* sidが空である場合 */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
144 p = sid;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
145 if ( strlen(p) == 0 )
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
146 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
147 sid_list[0] = NULL;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
148 return sid_list;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
149 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
150
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
151 /* カンマ無し */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
152 if ( CommaNum == 0 )
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
153 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
154 sid_list[0] = sid;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
155 sid_list[1] = NULL;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
156 return sid_list;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
157 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
158
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
159 /* カンマ区切りで複数指定時 */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
160 i=0;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
161 p = sid;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
162 /* 文字列端に到達するか、カンマ数が数えた数に達したら終了 */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
163 while((*p != '\0') || i < CommaNum)
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
164 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
165 /* 現在の処理位置をsid_list[i]にセット */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
166 /* このタイミングの p は
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
167 * ・sid先頭
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
168 * ・[,]の次の文字
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
169 * いずれかであるので p を sid_list[i] に代入してよい
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
170 */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
171 sid_list[i] = p;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
172 i++;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
173
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
174 /* 最初に現れる[,]をNULL文字で置換する */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
175 p = strchr(p, C_CHAR_COMMA);
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
176 if ( p == NULL )
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
177 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
178 /* カンマが見つからない場合は最後の処理対象なので終了 */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
179 break;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
180 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
181 *p = '\0';
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
182 /* 処理位置をNULLで置換した文字の次の位置に設定する */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
183 p++;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
184 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
185
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
186 /* 最後のsid_list[n]はNULLポインタで止める */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
187 sid_list[i] = NULL;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
188
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
189 i=0;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
190 while( sid_list[i] != NULL )
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
191 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
192 i++;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
193 }
98
3fd15032fd3a tweak user interface for sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 96
diff changeset
194 #if 0
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
195 for(i=0; sid_list[i] != NULL; i++)
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
196 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
197 printf("sid_list[%d]=[%s].\n",i, sid_list[i]);
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
198 }
98
3fd15032fd3a tweak user interface for sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 96
diff changeset
199 #endif
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
200 return sid_list;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
201 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
202
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
203 /**
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
204 * 初期化処理
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
205 */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
206 splitter* split_startup(
121
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
207 char *sid, // [in] サービスID(引数で指定した文字列)
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
208 char *filename, // [in] 出力ESファイル名(引数で指定したファイル名)
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
209 char *arg_cue // [in] 録画開始時刻(引数で指定した文字列 YYYYMMDDHHMISS)
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
210 )
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
211 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
212 splitter* sp;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
213 int i;
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
214 sp = malloc(sizeof(splitter));
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
215 if ( sp == NULL )
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
216 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
217 fprintf(stderr, "split_startup malloc error.\n");
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
218 return NULL;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
219 }
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
220 sp->program = malloc( sizeof(program_t) * MAX_SERVICE_ID );
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
221 if ( sp->program == NULL )
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
222 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
223 fprintf(stderr, "split_startup malloc error.\n");
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
224 return NULL;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
225 }
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
226 memset(sp->pids, 0, sizeof(sp->pids));
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
227 memset(sp->pmt_pids, 0, sizeof(sp->pmt_pids));
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
228 memset(sp->cat_pids, 0, sizeof(sp->cat_pids));
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
229 memset(sp->pcr_pids, 0, sizeof(sp->pcr_pids));
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
230 memset(sp->pcr, 0, sizeof(sp->pcr));
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
231
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
232 sp->sid_list = NULL;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
233 sp->pat = NULL;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
234 sp->sid_list = AnalyzeSid(sid);
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
235 if ( sp->sid_list == NULL )
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
236 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
237 free(sp);
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
238 return NULL;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
239 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
240 sp->pat_count = 0xFF;
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
241 sp->pmt_retain = -1;
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
242 sp->pmt_counter = 0;
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
243 sp->time_cue = 0;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
244 sp->time_tot = 0;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
245 sp->pcr_nb = 0;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
246 memset(sp->esbuf, 0, sizeof(splitesbuf_t *)*MAX_PID);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
247 memset(sp->pesbuf, 0, sizeof(splitpesbuf_t *)*MAX_PID);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
248 memset(sp->program, 0, sizeof(program_t *)*MAX_SERVICE_ID);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
249 for ( i=0; i < MAX_PID; i++ ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
250 /* pmt_version は (N%32) の値を取るので、0 で初期化してはならない */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
251 sp->program[i].pmt_version = -1;
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
252 /* cue は最大値で初期化(CUE <= STCとなると録画開始するため) */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
253 sp->program[i].cue = INT64_MAX;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
254 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
255 memset(sp->pid_sid_table, 0, sizeof(int)*MAX_PID);
146
066f33b2213a EXPERIMENTAL: Select a particular program from multi-channel.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 143
diff changeset
256 sp->filename = NULL;
066f33b2213a EXPERIMENTAL: Select a particular program from multi-channel.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 143
diff changeset
257 sp->esout = 0;
121
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
258 if ( filename != NULL ) {
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
259 sp->esout = 1;
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
260 sp->filename = filename;
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
261 }
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
262 if ( arg_cue != NULL ) {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
263 sp->arg_cue = arg_cue;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
264 } else {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
265 sp->arg_cue = "00000000000000"; /* とりあえず最小値 */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
266 }
164
7d8a5bb874ad EXPERIMENTAL: Change phisical channel by mq_recv().
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 152
diff changeset
267 sp->split_select_finish = TSS_ERROR;
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
268 return sp;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
269 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
270
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
271 /**
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
272 * 落とすPIDを確定させる
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
273 */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
274 int split_select(
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
275 splitter *sp, // [in/out] splitter構造体
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
276 ARIB_STD_B25_BUFFER *sbuf // [in] 入力TS
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
277 )
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
278 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
279 int result;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
280 // TS解析
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
281 result = ReadTs(sp, sbuf);
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
282
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
283 return result;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
284 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
285
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
286 /**
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
287 * 終了処理
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
288 */
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
289 void split_shutdown(splitter* sp)
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
290 {
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
291 int i = 0;
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
292 if ( sp != NULL ) {
146
066f33b2213a EXPERIMENTAL: Select a particular program from multi-channel.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 143
diff changeset
293 if ( sp->program != NULL )
066f33b2213a EXPERIMENTAL: Select a particular program from multi-channel.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 143
diff changeset
294 {
066f33b2213a EXPERIMENTAL: Select a particular program from multi-channel.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 143
diff changeset
295 free(sp->program);
066f33b2213a EXPERIMENTAL: Select a particular program from multi-channel.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 143
diff changeset
296 sp->program = NULL;
066f33b2213a EXPERIMENTAL: Select a particular program from multi-channel.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 143
diff changeset
297 }
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
298 if ( sp->pat != NULL )
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
299 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
300 free(sp->pat);
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
301 sp->pat = NULL;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
302 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
303 if ( sp->sid_list != NULL )
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
304 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
305 free(sp->sid_list);
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
306 sp->sid_list = NULL;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
307 }
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
308 for(i=0; i < MAX_PID; i++) {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
309 if ( sp->esbuf[i] != NULL ) {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
310 if ( sp->esbuf[i]->fd != -1 ) {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
311 close(sp->esbuf[i]->fd);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
312 sp->esbuf[i]->fd = -1;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
313 }
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
314 free(sp->esbuf[i]);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
315 sp->esbuf[i] = NULL;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
316 }
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
317 if ( sp->pesbuf[i] != NULL ) {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
318 free(sp->pesbuf[i]);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
319 sp->pesbuf[i] = NULL;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
320 }
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
321 }
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
322 free(sp);
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
323 sp = NULL;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
324 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
325 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
326
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
327 /**
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
328 * TS 解析処理
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
329 *
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
330 * 対象のチャンネル番号のみの PAT の再構築と出力対象 PID の抽出を行う
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
331 */
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
332 static int ReadTs(splitter *sp, ARIB_STD_B25_BUFFER *sbuf)
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
333 {
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
334 #if 0
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
335 splitter *sp, // [in/out] splitter構造体
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
336 ARIB_STD_B25_BUFFER *sbuf, // [in] pt1_drvの入力TS
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
337 #endif
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
338
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
339 int length = sbuf->size;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
340 int pid;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
341 int result = TSS_ERROR;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
342 int index;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
343
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
344 index = 0;
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
345 while(length - index - LENGTH_PACKET > 0) {
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
346 pid = GetPid(sbuf->data + index + 1);
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
347 // PAT
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
348 if(PAT == pid) {
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
349 result = AnalyzePat(sp, sbuf->data + index);
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
350 if(TSS_SUCCESS != result) {
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
351 /* 下位の関数内部でmalloc error発生 */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
352 return result;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
353 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
354 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
355
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
356 // PMT
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
357 /* 残すpmt_pidである場合には、pmtに書かれている
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
358 * 残すべきPCR/AUDIO/VIDEO PIDを取得する */
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
359 if(sp->pmt_pids[pid] == 1) {
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
360 /* この中にはPMT毎に一度しか入らないようにしておく */
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
361 sp->pmt_pids[pid]++;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
362 sp->pmt_counter += 1;
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
363 DemuxTs(sbuf->data +index, sp, pid); /* AnalyzePmt より DemuxTs の方がアダプテーションフィールドの処理が良いので変更 */
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
364 }
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
365 /* 録画する全てのPMTについて、中にあるPCR/AUDIO/VIDEOのPIDを得る */
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
366 /* pmt_counter と pmt_retain が一致する場合に条件は満たされる */
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
367 if(sp->pmt_counter == sp->pmt_retain) {
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
368 result = TSS_SUCCESS;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
369 break;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
370 }
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
371 else {
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
372 result = TSS_ERROR;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
373 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
374 index += LENGTH_PACKET;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
375 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
376
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
377 return(result);
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
378 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
379
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
380 /**
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
381 * TS 分離処理
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
382 */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
383 int split_ts(
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
384 splitter *sp, // [in] splitterパラメータ
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
385 ARIB_STD_B25_BUFFER *sbuf, // [in] 入力TS
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
386 splitbuf_t *dbuf // [out] 出力TS
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
387 )
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
388 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
389 int pid;
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
390 unsigned char *sptr, *dptr;
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
391 int s_offset = 0;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
392 int d_offset = 0;
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
393 int64_t pcr_h = 0;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
394 int pcr_l = 0;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
395 int ret = 0;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
396 int sid = 0;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
397 program_t *program;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
398 static int packet_nb; /* パケット受信数 */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
399 int i = 0;
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
400
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
401 /* 初期化 */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
402 dbuf->size = 0;
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
403 if (sbuf->size < 0) {
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
404 return TSS_ERROR;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
405 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
406
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
407 sptr = sbuf->data;
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
408 dptr = dbuf->buffer;
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
409
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
410 while(sbuf->size > s_offset) {
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
411 pid = GetPid(sptr + s_offset + 1);
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
412 sid = sp->pid_sid_table[pid]; /* PIDからSIDを取得 */
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
413 switch(pid) {
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
414
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
415 // PAT
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
416 case PAT:
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
417 // 巡回カウンタカウントアップ
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
418 if(0xFF == sp->pat_count) {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
419 sp->pat_count = sp->pat[3];
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
420 }
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
421 else {
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
422 sp->pat_count += 1;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
423 if(0 == sp->pat_count % 0x10) {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
424 sp->pat_count -= 0x10;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
425 }
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
426 }
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
427 sp->pat[3] = sp->pat_count;
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
428
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
429 memcpy(dptr + d_offset, sp->pat, LENGTH_PACKET);
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
430 d_offset += LENGTH_PACKET;
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
431 dbuf->size += LENGTH_PACKET;
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
432 break;
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
433 case TOT:
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
434 /* TOT に TDTの情報全てが含まれており、実放送では TOT しか送信されない */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
435 /* TOT は 500msec の誤差が保証されている
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
436 * 閏秒の場合は最大1.5秒の誤差となる
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
437 */
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
438 if ( sp->time_tot == 0 ) {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
439 /* splitter構造体の時刻関係(TOT/CUE)のパラメータ初期化 */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
440 parse_tot(sptr + s_offset, &(sp->time_tot));
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
441 sp->time_cue = cue2time(sp->arg_cue);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
442 sp->tot_packet_nb = packet_nb;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
443 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
444 break;
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
445 default:
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
446 /* ■時間管理に関しての実装方針■ */
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
447 /*
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
448 * ■時間関係を扱っている変数■
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
449 * PCR : 42Bit @27MHz(ServiceID(ProgramID, sid)毎に独立)
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
450 * PTS : 42Bit @90KHz(ES毎に独立)
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
451 * DTS : 42Bit @90KHz(ES毎に独立)
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
452 * TOT : MJD + 2進化10進数(TSに1つだけ)
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
453 * STC : 64Bit @27MHz(ServiceID(ProgramID, sid)の現在時刻(ソースはPCR))
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
454 * CUE : 録画開始時刻 YYYYMMDDHHMISS (引数指定)
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
455 *
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
456 * ■STCの管理方針■
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
457 * PCR受信時にSTCに時間情報をコピーする
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
458 * 1パケットを受信すると経過する時間を加算してSTCを管理する
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
459 * (ffmpegのmpegts.cと同じ方針)
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
460 *
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
461 * ■CUEとTOTとSTC■
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
462 * TOTからSTCと比較するための情報を作成する。
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
463 * ・TOTは time_t
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
464 * ・CUEは time_t
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
465 * ・STCは42Bitの27MHz周期の数値
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
466 * TOT 受信時に各Program(ServiceID)のSTCを変換基準値とする
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
467 * 録画開始時(27MHz)の値の計算式は、
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
468 * Program->CUE = STCの変換基準値 + 27e6*(ARG_CUE-TOT(秒))
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
469 * 録画の開始確認として Program->CUE と PTS を比較すればよい
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
470 *
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
471 * ※PCR/PTS/DTSはオーバーフローしたときには34Bit目が立っていると見なすこと※
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
472 * オーバーフロー時の処理は未実装
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
473 */
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
474 if ( 2 == sp->pmt_pids[pid] ) {
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
475 /* PMT の追跡 */
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
476 DemuxTs((sptr+s_offset), sp, pid);
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
477 }
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
478 /* pids[pid] が 1 は残すパケットなので書き込む */
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
479 if ( (1 == sp->pids[pid]) ) {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
480 /* PCRとSTCの処理 */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
481 int pcr_index;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
482 pcr_index = search_pcr_pid(sp, pid);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
483 if ( sp->pcr_pids[pid] == 1 && pcr_index != -1) { /* PCRか否か */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
484 ret = parse_pcr(&pcr_h, &pcr_l, (sptr+s_offset));
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
485 /*
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
486 * PCR は複数 ServiceID(ProgramID)で重複利用される場合がある
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
487 * PCR を参照する複数の ServiceID(ProgramID)分ループ
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
488 */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
489 for (i=0; i < sp->pcr[pcr_index].sid_nb; i++) {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
490 sid = sp->pcr[pcr_index].sid[i];
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
491 program = &(sp->program[sid]);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
492 /* こっから */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
493 if ( ret == 0 ) { /* PCR の解析に成功 */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
494 program->stc = pcr_h * 300 + pcr_l; /* PCR受信時にSTCを補正*/
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
495 if ( program->pcr1 == 0 ) {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
496 program->pcr1 = program->stc;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
497 printf("pcr1 pid[%d] sid[%d] packet_nb[%d] sid_nb[%d] i[%d]\n",
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
498 pid, sid, packet_nb, sp->pcr[pcr_index].sid_nb, i);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
499 } else if ( program->pcr2 == 0 ) {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
500 // printf("pcr2 pid[%d] sid[%d] packet_nb[%d], p_packet_nb[%d] sid_nb[%d] i[%d]\n",
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
501 // pid, sid, packet_nb, program->pcr_packet_nb, sp->pcr[pcr_index].sid_nb, i);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
502 program->pcr2 = program->stc;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
503 program->pcr_incr = (program->pcr2 -program->pcr1)
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
504 /(packet_nb -program->pcr_packet_nb);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
505 printf("pcr2 pid[%d] sid[%d] pcr_incr[%llu]\n",
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
506 pid, sid, program->pcr_incr);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
507 } else {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
508 /* PCR処理済み */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
509 ; /* 得に処理無し */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
510 }
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
511 if ( (program->cue == INT64_MAX ) &&
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
512 (sp->arg_cue != NULL) &&
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
513 (sp->time_tot != 0) ) { /* 録画開始時刻指定時 */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
514 /*
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
515 * 録画開始時刻 = STC +(CUE -TOT)*27MHz
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
516 * +(TOT取得時から現在までのパケット数の増分)*パケットあたりの進む時間
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
517 * -0.49秒(この数字は適当)
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
518 * TOT/STCで時間調整して、GOP先頭から出すので攻めてしまっていい気がする
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
519 */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
520 program->cue = program->stc
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
521 +(sp->time_cue -sp->time_tot)*27e6
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
522 +(packet_nb -sp->tot_packet_nb)*program->pcr_incr
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
523 -(27e6*49/100);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
524 printf("STC[%llu] CUE[%llu] SID[%d]\n",
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
525 program->stc, program->cue, sid);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
526 }
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
527 program->pcr_packet_nb = packet_nb;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
528 program->packet_nb = packet_nb;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
529 } else if ( program->pcr_incr ) { /* PCRの解析に失敗且つpcr_incr変数の計算済み*/
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
530 /* STCを成長させる */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
531 program->stc += (packet_nb -program->packet_nb)*program->pcr_incr;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
532 program->packet_nb = packet_nb;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
533 } else {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
534 ; /* STCを進める要素が揃ってません */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
535 }
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
536 } /* for */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
537 } else { /* 処理対象パケットはPCRではない */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
538 program = &(sp->program[sid]);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
539 if ( program->pcr_incr ) { /* PCRを受信しない且つpcr_incr変数の計算済み */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
540 /* STCを成長させる */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
541 program->stc += (packet_nb -program->packet_nb)*program->pcr_incr;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
542 program->packet_nb = packet_nb;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
543 } else { /* それ以外 */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
544 ; /* STCを進める要素が揃ってません */
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
545 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
546 }
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
547 #if 0
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
548 // NHK Gを ALL とすると SID 1024 しか出ない...orz..
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
549 if ( !(packet_nb % 1000) ) {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
550 program = &(sp->program[sid]);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
551 printf("STC[%llu] SID[%d]\n", program->stc, sid);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
552 }
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
553 #endif
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
554 /* TS処理 */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
555 DemuxTs((sptr+s_offset), sp, pid);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
556 memcpy(dptr + d_offset, sptr + s_offset, LENGTH_PACKET);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
557 d_offset += LENGTH_PACKET;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
558 dbuf->size += LENGTH_PACKET;
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
559 }
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
560 break;
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
561 } /* switch */
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
562 s_offset += LENGTH_PACKET;
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
563 packet_nb += 1; /* パケット受信数加算 */
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
564 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
565 return(TSS_SUCCESS);
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
566 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
567
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
568 /**
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
569 * PAT 解析処理
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
570 *
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
571 * PAT を解析し、出力対象チャンネルが含まれているかチェックを行い、PAT を再構築する
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
572 */
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
573 static int AnalyzePat(splitter *sp, unsigned char *buf)
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
574 #if 0
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
575 unsigned char* buf, // [in] 読み込んだバッファ
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
576 unsigned char** pat, // [out] PAT 情報(再構築後)
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
577 unsigned char* pids, // [out] 出力対象 PID 情報
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
578 char** sid_list, // [in] 出力対象サービス ID のリスト
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
579 unsigned char* pmt_pids, // [out] サービス ID に対応する PMT の PID
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
580 int* pmt_retain // [out] 残すPMTの数
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
581 )
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
582 #endif
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
583 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
584 int pos[MAX_PID];
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
585 int service_id;
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
586 int i, j, k;
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
587 int size = 0;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
588 int pid;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
589 int result = TSS_SUCCESS;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
590 char **p;
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
591 int sid_found = FALSE;
98
3fd15032fd3a tweak user interface for sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 96
diff changeset
592 int avail_sids[MAX_SERVICES];
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
593
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
594 unsigned char *pat = sp->pat;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
595 unsigned char *pids = sp->pids;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
596 char **sid_list = sp->sid_list;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
597 unsigned char *pmt_pids = sp->pmt_pids;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
598
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
599 char chosen_sid[512];
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
600 chosen_sid[0] = '\0';
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
601
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
602 if(pat == NULL) {
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
603 /* 初期化 */
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
604 sp->pmt_retain = 0;
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
605 memset(pos, 0, sizeof(pos));
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
606 size = buf[7];
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
607
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
608 /* prescan SID/PMT */
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
609 for(i = 17, j = 0; i < (size + 8) - 4; i = i + 4, j++) {
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
610 avail_sids[j] = (buf[i] << 8) + buf[i+1];
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
611 sp->avail_pmts[j] = GetPid(&buf[i+2]);
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
612 }
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
613 sp->num_pmts = j;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
614
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
615 // 対象チャンネル判定
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
616 /* size + 8 = パケット全長 */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
617 /* 最終 4 バイトはCRCなので飛ばす */
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
618 for(i = 17; i < (size + 8) - 4; i = i + 4) {
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
619
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
620 service_id = (buf[i] << 8) + buf[i+1];
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
621 p = sid_list;
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
622
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
623 while(*p) {
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
624 if(service_id == atoi(*p)) {
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
625 /* 録画対象の pmt_pids は 1 とする */
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
626 /* 録画対象の pmt の pids は 1 とする */
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
627 /* 対応する pid_sid_table に サービスID(ProgramID) を入れる */
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
628 pid = GetPid(&buf[i + 2]);
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
629 *(pmt_pids+pid) = 1;
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
630 *(pids+pid) = 1;
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
631 pos[pid] = i;
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
632 sid_found = TRUE;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
633 sp->pmt_retain += 1;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
634 sp->program[service_id].pmt_packet_id = pid;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
635 sp->pid_sid_table[pid] = service_id;
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
636 sprintf(chosen_sid, "%s %d", *chosen_sid ? chosen_sid : "", service_id);
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
637 p++;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
638 continue;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
639 }
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
640 else if(!strcasecmp(*p, "hd") || !strcasecmp(*p, "sd1")) {
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
641 /* hd/sd1 指定時には1番目のサービスを保存する */
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
642 if(service_id == avail_sids[0]) {
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
643 pid = GetPid(&buf[i + 2]);
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
644 *(pmt_pids+pid) = 1;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
645 *(pids+pid) = 1;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
646 pos[pid] = i;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
647 sid_found = TRUE;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
648 sp->pmt_retain += 1;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
649 sp->program[service_id].pmt_packet_id = pid;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
650 sp->pid_sid_table[pid] = service_id;
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
651 sprintf(chosen_sid, "%s %d", *chosen_sid ? chosen_sid : "", service_id);
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
652 }
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
653 p++;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
654 continue;
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
655 }
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
656 else if(!strcasecmp(*p, "sd2")) {
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
657 /* sd2 指定時には2番目のサービスを保存する */
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
658 if(service_id == avail_sids[1]) {
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
659 pid = GetPid(&buf[i + 2]);
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
660 *(pmt_pids+pid) = 1;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
661 *(pids+pid) = 1;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
662 pos[pid] = i;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
663 sid_found = TRUE;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
664 sp->pmt_retain += 1;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
665 sp->program[service_id].pmt_packet_id = pid;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
666 sp->pid_sid_table[pid] = service_id;
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
667 sprintf(chosen_sid, "%s %d", *chosen_sid ? chosen_sid : "", service_id);
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
668 }
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
669 p++;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
670 continue;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
671 }
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
672 else if(!strcasecmp(*p, "sd3")) {
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
673 /* sd3 指定時には3番目のサービスを保存する */
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
674 if(service_id == avail_sids[2]) {
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
675 pid = GetPid(&buf[i + 2]);
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
676 *(pmt_pids+pid) = 1;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
677 *(pids+pid) = 1;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
678 pos[pid] = i;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
679 sid_found = TRUE;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
680 sp->pmt_retain += 1;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
681 sp->program[service_id].pmt_packet_id = pid;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
682 sp->pid_sid_table[pid] = service_id;
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
683 sprintf(chosen_sid, "%s %d", *chosen_sid ? chosen_sid : "", service_id);
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
684 }
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
685 p++;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
686 continue;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
687 }
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
688 else if(!strcasecmp(*p, "1seg")) {
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
689 /* 1seg 指定時には PMTPID=0x1FC8 のサービスを保存する */
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
690 pid = GetPid(&buf[i + 2]);
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
691 if(pid == 0x1FC8) {
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
692 *(pmt_pids+pid) = 1;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
693 *(pids+pid) = 1;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
694 pos[pid] = i;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
695 sid_found = TRUE;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
696 sp->pmt_retain += 1;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
697 sp->program[service_id].pmt_packet_id = pid;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
698 sp->pid_sid_table[pid] = service_id;
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
699 sprintf(chosen_sid, "%s %d", *chosen_sid ? chosen_sid : "", service_id);
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
700 }
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
701 p++;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
702 continue;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
703 }
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
704 else if(!strcasecmp(*p, "all")) {
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
705 /* all指定時には全保存する */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
706 pid = GetPid(&buf[i + 2]);
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
707 *(pmt_pids+pid) = 1;
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
708 *(pids+pid) = 1;
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
709 pos[pid] = i;
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
710 sid_found = TRUE;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
711 sp->pmt_retain += 1;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
712 sp->program[service_id].pmt_packet_id = pid;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
713 sp->pid_sid_table[pid] = service_id;
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
714 sprintf(chosen_sid, "%s %d", *chosen_sid ? chosen_sid : "", service_id);
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
715 break;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
716 }
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
717
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
718 p++;
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
719 } /* while */
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
720 }
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
721
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
722 /* if sid has been specified but no sid found, fall back to all */
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
723 if(*sid_list && !sid_found) {
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
724 for(i = 17; i < (size + 8) - 4; i = i + 4) {
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
725 service_id = (buf[i] << 8) + buf[i+1];
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
726 pid = GetPid(&buf[i + 2]);
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
727 *(pmt_pids+pid) = 1;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
728 *(pids+pid) = 1;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
729 pos[pid] = i;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
730 sid_found = TRUE;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
731 sp->pmt_retain += 1;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
732 sp->program[service_id].pmt_packet_id = pid;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
733 sp->pid_sid_table[pid] = service_id;
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
734 sprintf(chosen_sid, "%s %d", *chosen_sid ? chosen_sid : "", service_id);
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
735 }
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
736 }
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
737
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
738 /* print SIDs */
98
3fd15032fd3a tweak user interface for sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 96
diff changeset
739 fprintf(stderr, "Available sid = ");
152
30e91361506a EXPERIMENTAL: Enable change phisical channel by DLNA.(ISDB-T only)
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 149
diff changeset
740 for(k=0; k < sp->num_pmts; k++)
98
3fd15032fd3a tweak user interface for sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 96
diff changeset
741 fprintf(stderr, "%d ", avail_sids[k]);
3fd15032fd3a tweak user interface for sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 96
diff changeset
742 fprintf(stderr, "\n");
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
743 fprintf(stderr, "Chosen sid =%s\n", chosen_sid);
98
3fd15032fd3a tweak user interface for sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 96
diff changeset
744
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
745 #if 0
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
746 /* print PMTs */
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
747 fprintf(stderr, "Available PMT = ");
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
748 for(k=0; k < sp->num_pmts; k++)
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
749 fprintf(stderr, "%d ", sp->avail_pmts[k]);
98
3fd15032fd3a tweak user interface for sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 96
diff changeset
750 fprintf(stderr, "\n");
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
751 #endif
98
3fd15032fd3a tweak user interface for sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 96
diff changeset
752
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
753 // PAT 再構築
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
754 result = RecreatePat(sp, buf, pos);
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
755 #if 0
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
756 int tc;
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
757 for(tc=0; tc<188; tc++)
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
758 fprintf(stderr, "%02x ", *(pat+tc));
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
759 #endif
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
760 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
761
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
762 return(result);
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
763 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
764
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
765 /**
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
766 * PAT 再構築処理
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
767 *
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
768 * PMT から出力対象チャンネル以外のチャンネル情報を削除し、PAT を再構築する
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
769 */
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
770 static int RecreatePat(splitter *sp, unsigned char *buf, int *pos)
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
771 #if 0
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
772 unsigned char* buf, // [in] 読み込んだバッファ
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
773 unsigned char** pat, // [out] PAT 情報(再構築後)
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
774 unsigned char* pids, // [out] 出力対象 PID 情報
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
775 int *pos) // [in] 取得対象 PMT のバッファ中の位置
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
776 #endif
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
777 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
778 unsigned char y[LENGTH_CRC_DATA];
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
779 int crc;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
780 int i;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
781 int j;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
782 int pos_i;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
783 int pid_num = 0;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
784
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
785 // CRC 計算のためのデータ
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
786 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
787 // チャンネルによって変わらない部分
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
788 for (i = 0; i < LENGTH_PAT_HEADER; i++)
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
789 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
790 y[i] = buf[i + 5];
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
791 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
792 // チャンネルによって変わる部分
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
793 for (i = 0; i < MAX_PID; i++)
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
794 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
795 if(pos[i] != 0)
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
796 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
797 /* buf[pos_i] を y にコピー(抽出したPIDの数) */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
798 pos_i = pos[i];
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
799 for (j = 0; j < 4; j++)
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
800 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
801 y[LENGTH_PAT_HEADER + ((4*pid_num) + j)] = buf[pos_i + j];
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
802 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
803 pid_num++;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
804 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
805 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
806 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
807 /* パケットサイズ計算 */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
808 y[2] = pid_num * 4 + 0x0d;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
809 // CRC 計算
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
810 crc = GetCrc32(y, LENGTH_PAT_HEADER + pid_num*4);
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
811
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
812 // PAT 再構成
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
813 sp->pat = (unsigned char*)malloc(LENGTH_PACKET);
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
814 if(sp->pat == NULL)
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
815 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
816 fprintf(stderr, "RecreatePat() malloc error.\n");
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
817 return(TSS_NULL);
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
818 }
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
819 memset(sp->pat, 0xFF, LENGTH_PACKET);
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
820 for (i = 0; i < 5; i++)
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
821 {
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
822 (sp->pat)[i] = buf[i];
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
823 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
824 for (i = 0; i < LENGTH_PAT_HEADER + pid_num*4; i++)
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
825 {
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
826 (sp->pat)[i + 5] = y[i];
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
827 }
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
828 (sp->pat)[5 + LENGTH_PAT_HEADER + pid_num*4] = (crc >> 24) & 0xFF;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
829 (sp->pat)[6 + LENGTH_PAT_HEADER + pid_num*4] = (crc >> 16) & 0xFF;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
830 (sp->pat)[7 + LENGTH_PAT_HEADER + pid_num*4] = (crc >> 8) & 0xFF;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
831 (sp->pat)[8 + LENGTH_PAT_HEADER + pid_num*4] = (crc ) & 0xFF;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
832
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
833 return(TSS_SUCCESS);
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
834 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
835
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
836
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
837 /**
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
838 * PMT 解析処理
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
839 *
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
840 * PMT を解析し、保存対象の PID を特定する
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
841 * TSヘッダとアダプテーションフィールドの処理は DemuxTs に一任するので、
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
842 * この内部では、セクションデータの先頭ポインタをもらってくる
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
843 */
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
844 static int AnalyzePmt(splitter *sp, const uint8_t *buf, int sid, const int size)
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
845 #if 0
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
846 unsigned char* buf, // [in] セクション先頭
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
847 unsigned char* pids) // [out] 出力対象 PID 情報
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
848 #endif
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
849 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
850 unsigned char Nall;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
851 unsigned char N;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
852 int pcr;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
853 int epid;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
854 int av_flag = 0;
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
855 int i = 0;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
856 int j = 0;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
857 int pcr_found = 0;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
858 /* デバッグ用 PMT情報表示 */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
859 #define PmtDebug (1)
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
860
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
861 #ifdef PmtDebug
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
862 printf("AnalyzePmt start. Tree List enable.\n");
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
863 printf("SID[%d][0x%04x]\n", sid, sid);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
864 #endif
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
865
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
866 // Nall = ((buf[2] & 0x0F) << 4) + buf[3];
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
867 Nall = ((buf[2] & 0x0F) << 8) + buf[3];
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
868 // ここで受け取るのはTSパケットではなく、セクションの先頭ポインタであるのでsizeで見る
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
869 // if(Nall > LENGTH_PACKET)
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
870 // Nall = LENGTH_PACKET - 8; /* xxx workaround --yaz */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
871 if(Nall > size)
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
872 Nall = size -8;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
873
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
874 /* get version */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
875 sp->program[sid].pmt_version = get_pmt_version(buf);
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
876 #ifdef PmtDebug
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
877 printf(" pmt_version[%02x]\n", sp->program[sid].pmt_version);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
878 #endif
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
879
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
880 // PCR
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
881 pcr = GetPid(&buf[9]);
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
882 sp->pids[pcr] = 1;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
883 sp->program[sid].pcr_packet_id = pcr;
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
884 sp->pid_sid_table[pcr] = sid; /* PCRは重複する可能性があるので方式がよろしくない */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
885 sp->pcr_pids[pcr] = 1;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
886
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
887 /* PCRの重複チェック(複数ServiceID(ProgramID)) */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
888 for( i=0; i < sp->pcr_nb; i++ ) {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
889 if ( sp->pcr[i].pid == pcr ) {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
890 /* 発見 */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
891 for ( j=0; j < sp->pcr[i].sid_nb; j++ ) {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
892 /* 同一SIDが既に登録されているか確認 */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
893 if ( sp->pcr[i].sid[j] == sid ) {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
894 pcr_found = 1;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
895 break;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
896 }
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
897 }
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
898 if ( pcr_found ) {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
899 /* 同一SIDが既に登録されている */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
900 #ifdef PmtDebug
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
901 printf(" same sid found pcr[%d] sid[%d]\n", pcr, sid);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
902 #endif
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
903 break;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
904 }
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
905 /* 重複PCR発見 */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
906 #ifdef PmtDebug
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
907 printf(" same pcr found pcr[%d] sid[%d] sid_nb[%d], i[%d]\n", pcr, sid, sp->pcr[i].sid_nb, i);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
908 #endif
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
909 sp->pcr[i].sid[sp->pcr[i].sid_nb] = sid;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
910 sp->pcr[i].sid_nb += 1;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
911 pcr_found = 1;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
912 break;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
913 }
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
914 }
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
915
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
916 if ( ! pcr_found ) {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
917 /* PCR管理領域更新 */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
918 #ifdef PmtDebug
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
919 printf(" new pcr found pcr[%d] sid[%d], pcr_nb[%d]\n", pcr, sid, sp->pcr_nb);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
920 #endif
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
921 sp->pcr[sp->pcr_nb].pid = pcr;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
922 sp->pcr[sp->pcr_nb].sid[0] = sid;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
923 sp->pcr[sp->pcr_nb].sid_nb = 1;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
924 sp->pcr_nb += 1;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
925 }
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
926 #ifdef PmtDebug
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
927 printf(" PCR PacketID[%d][0x%04x]\n", pcr, pcr);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
928 #endif
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
929
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
930 // N = ((buf[11] & 0x0F) << 4) + buf[12] + 16 + 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
931 N = ((buf[11] & 0x0F) << 8) + buf[12] + 12 + 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
932 // printf("NAll[%d] N[%d]\n", Nall, N);
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
933
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
934 // ECM
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
935 //int p = 17;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
936 int p = 13;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
937 while(p < N) {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
938 if ( p > size -4) {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
939 break;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
940 }
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
941 uint32_t cat_pid;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
942 uint32_t tag;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
943 uint32_t len;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
944
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
945 tag = buf[p];
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
946 len = buf[p+1];
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
947 p += 2;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
948
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
949 if(tag == 0x09 && len >= 4 && p+len <= N) {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
950 // ca_pid = ((buf[p+2] << 8) | buf[p+3]) & 0x1fff;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
951 cat_pid = (AV_RB16(buf+p+2)) & 0x1fff;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
952 sp->pids[cat_pid] = 1;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
953 sp->cat_pids[cat_pid] = 1;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
954 sp->pid_sid_table[cat_pid] = sid; /* CATも複数ServiceIDで重複がある */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
955 #ifdef PmtDebug
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
956 printf(" CAT PacketID[%d][0x%04x]\n", cat_pid, cat_pid);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
957 #endif
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
958 }
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
959 p += len;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
960 }
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
961
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
962 /*
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
963 * ISO/IEC 13818-1:2000(E) Table 2-29 - Stream type assignments
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
964 * Value Desctiption
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
965 * 0x00 ITU-T | ISO/IEC Reserved
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
966 * 0x01 ISO/IEC 11172 Video
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
967 * 0x02 ITU-T Rec. H.262 | ISO/IEC 13818-2 Video or ISO/IEC 11172-2 constrained parameter video stream
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
968 * 0x03 ISO/IEC 11172 Audio
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
969 * 0x04 ISO/IEC 13818-3 Audio
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
970 * 0x05 ITU-T Rec. H.222.0 | ISO/IEC 13818-1 private_sections
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
971 * 0x06 ITU-T Rec. H.222.0 | ISO/IEC 13818-1 PES packets containing private data
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
972 * 0x07 ISO/IEC 13522 MHEG
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
973 * 0x08 ITU-T Rec. H.222.0 | ISO/IEC 13818-1 Annex A DSM-CC
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
974 * 0x09 ITU-T Rec. H.222.1
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
975 * 0x0A ISO/IEC 13818-6 type A
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
976 * 0x0B ISO/IEC 13818-6 type B
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
977 * 0x0C ISO/IEC 13818-6 type C
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
978 * 0x0D ISO/IEC 13818-6 type D
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
979 * 0x0E ITU-T Rec. H.222.0 | ISO/IEC 13818-1 auxiliary
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
980 * 0x0F ISO/IEC 13818-7 Audio with ADTS transport syntax
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
981 * 0x10 ISO/IEC 14496-2 Visual
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
982 * 0x11 ISO/IEC 14496-3 Audio with the LATM transport syntax as defined in ISO/IEC 14496-3 / AMD 1
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
983 * 0x12 ISO/IEC 14496-1 SL-packetized stream or FlexMux stream carried in PES packets
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
984 * 0x13 ISO/IEC 14496-1 SL-packetized stream or FlexMux stream carried in ISO/IEC14496_sections.
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
985 * 0x14 ISO/IEC 13818-6 Synchronized Download Protocol
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
986 * 0x15-0x7F ITU-T Rec. H.222.0 | ISO/IEC 13818-1 Reserved
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
987 * 0x80-0xFF User Private
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
988 *
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
989 */
104
afd25d9ebef6 output ECM packet so that former workaround is no longer needed.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 101
diff changeset
990
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
991 // ES PID
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
992 while (N < Nall + 8 - 4) {
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
993 av_flag = 0;
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
994 // ストリーム種別が 0x0D(type D)は出力対象外
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
995 if (0x0D != buf[N]) {
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
996 epid = GetPid(&buf[N + 1]);
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
997 sp->pids[epid] = 1;
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
998 sp->pid_sid_table[epid] = sid;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
999 if ( buf[N] == 0x02 ) { /* 13818-2 Video */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1000 sp->program[sid].video[sp->program[sid].video_nb] = epid;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1001 sp->program[sid].video_nb += 1;
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1002 av_flag = TSS_STREAM_TYPE_VIDEO;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1003 #ifdef PmtDebug
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1004 printf(" VIDEO PacketID[%d][0x%04x] StreamType[0x%02x]\n", epid, epid, buf[N]);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1005 #endif
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1006 } else if ( (buf[N] == 0x04) || (buf[N] == 0x0f) ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1007 /* 13818-3 Audio or 13818-7 Audio with ADTS transport syntax */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1008 sp->program[sid].audio[sp->program[sid].audio_nb] = epid;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1009 sp->program[sid].audio_nb += 1;
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1010 av_flag = TSS_STREAM_TYPE_AUDIO;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1011 #ifdef PmtDebug
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1012 printf(" AUDIO PacketID[%d][0x%04x] StreamType[0x%02x]\n", epid, epid, buf[N]);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1013 #endif
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1014 } else {
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1015 #ifdef PmtDebug
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1016 printf(" OTHER PacketID[%d][0x%04x] StreamType[0x%02x]\n", epid, epid, buf[N]);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1017 #endif
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1018 ; /* A/V どちらでもないものはとりあえずスルー */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1019 }
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1020 if ( av_flag && sp->esout ) {
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1021 /* ESバッファはNULLか? */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1022 if ( sp->esbuf[epid] == NULL ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1023 sp->esbuf[epid] = malloc(sizeof(splitesbuf_t));
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1024 if ( sp->esbuf[epid] == NULL ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1025 fprintf(stderr, "malloc error\n");
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1026 return TSS_NULL;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1027 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1028 sp->esbuf[epid]->size = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1029 sp->esbuf[epid]->Program = &(sp->program[sid]);
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1030 sp->esbuf[epid]->fd = -1;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1031 if ( creat_es_file(sp, sid, epid, av_flag) ) {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1032 return TSS_ERROR;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1033 }
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1034 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1035 /* PESバッファはNULLか? */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1036 if ( sp->pesbuf[epid] == NULL ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1037 sp->pesbuf[epid] = malloc(sizeof(splitpesbuf_t));
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1038 if ( sp->pesbuf[epid] == NULL ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1039 fprintf(stderr, "malloc error\n");
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1040 return TSS_NULL;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1041 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1042 sp->pesbuf[epid]->size = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1043 sp->pesbuf[epid]->Program = &(sp->program[sid]);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1044 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1045 }
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
1046 }
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1047 // N += 4 + (((buf[N + 3]) & 0x0F) << 4) + buf[N + 4] + 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1048 N += 4 + (((buf[N + 3]) & 0x0F) << 8) + buf[N + 4] + 1;
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1049 }
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1050 #ifdef PmtDebug
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1051 printf("AnalyzePmt finish.\n");
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1052 #endif
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1053 return TSS_SUCCESS;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1054 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1055
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1056 /**
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1057 * CRC 計算
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1058 */
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
1059 static int GetCrc32(
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1060 unsigned char* data, // [in] CRC 計算対象データ
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1061 int len) // [in] CRC 計算対象データ長
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1062 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1063 int crc;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1064 int i, j;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1065 int c;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1066 int bit;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1067
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1068 crc = 0xFFFFFFFF;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1069 for (i = 0; i < len; i++)
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1070 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1071 char x;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1072 x = data[i];
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1073
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1074 for (j = 0; j < 8; j++)
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1075 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1076
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1077 bit = (x >> (7 - j)) & 0x1;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1078
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1079 c = 0;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1080 if (crc & 0x80000000)
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1081 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1082 c = 1;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1083 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1084
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1085 crc = crc << 1;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1086
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1087 if (c ^ bit)
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1088 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1089 crc ^= 0x04C11DB7;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1090 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1091
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1092 crc &= 0xFFFFFFFF;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1093 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1094 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1095
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1096 return crc;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1097 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1098
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1099 /**
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1100 * PID 取得
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1101 */
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
1102 static int GetPid(
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1103 unsigned char* data) // [in] 取得対象データのポインタ
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1104 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1105 return ((data[0] & 0x1F) << 8) + data[1];
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1106 }
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1107
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1108 /* return the 90kHz PCR and the extension for the 27MHz PCR. return
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1109 (-1) if not available */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1110 static int parse_pcr(int64_t *ppcr_high, int *ppcr_low,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1111 const uint8_t *packet)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1112 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1113 int afc, len, flags;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1114 const uint8_t *p;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1115 unsigned int v;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1116
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1117 afc = (packet[3] >> 4) & 3;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1118 if (afc <= 1)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1119 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1120 p = packet + 4;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1121 len = p[0];
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1122 p++;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1123 if (len == 0)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1124 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1125 flags = *p++;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1126 len--;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1127 if (!(flags & 0x10))
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1128 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1129 if (len < 6)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1130 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1131 v = AV_RB32(p);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1132 *ppcr_high = ((int64_t)v << 1) | (p[4] >> 7);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1133 *ppcr_low = ((p[4] & 1) << 8) | p[5];
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1134 return 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1135 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1136
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1137 /* pesbufが空か判定 (ret. 0:not empty / 1: empty) */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1138 static int pesbuf_empty(splitpesbuf_t *pesbuf){
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1139 return pesbuf->size == 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1140 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1141
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1142 /* pesbufをクリア */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1143 void pesbuf_clear(splitpesbuf_t *pesbuf){
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1144 pesbuf->size = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1145 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1146
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1147 /* pesbufにデータを追加 (ret. 0:success / -1:error) */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1148 static int pesbuf_add(splitpesbuf_t *pesbuf, const uint8_t *data, int len){
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1149 if(pesbuf->size + len > sizeof pesbuf->buffer){
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1150 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1151 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1152 memcpy(pesbuf->buffer +pesbuf->size, data, len);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1153 pesbuf->size += len;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1154 return 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1155 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1156
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1157 /* pesbufから、PESの先頭(packet_start_code_prefix)を探す */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1158 /* (ret. >=0:offset / -1: error) */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1159 static int pesbuf_packet_start_code_prefix(splitpesbuf_t *pesbuf){
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1160 uint8_t packet_start_code_prefix[3] = {0x00, 0x00, 0x01};
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1161 int i = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1162
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1163 /* 小さすぎる */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1164 if(pesbuf->size < sizeof packet_start_code_prefix){
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1165 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1166 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1167 /* 先頭で探す */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1168 if(!memcmp(pesbuf->buffer + i, packet_start_code_prefix, sizeof packet_start_code_prefix)){
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1169 return 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1170 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1171
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1172 #if 0
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1173 /* 先頭以外からも探す場合は、ここのコードを有効化する。 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1174 /* ただし、MPEG-Videoのstart_codeと同じなので、深追いしない方がいいと思う... */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1175 for(i = 0; i < pesbuf->size - sizeof packet_start_code_prefix; i++){
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1176 if(!memcmp(pesbuf->buffer + i, packet_start_code_prefix, sizeof packet_start_code_prefix)){
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1177 return i;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1178 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1179 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1180 #endif
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1181
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1182 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1183 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1184
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1185 /**
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1186 * TSの解析とDemuxを行う
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1187 */
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1188 static int DemuxTs(const uint8_t *packet, splitter *sp, const int pid)
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1189 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1190 /*
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1191 * PES先頭までの長さは
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1192 * 4byte : continity counter
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1193 * 27,28bit が adaptation fileld制御
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1194 * (01:ペイロードのみ, 10:adaptation fileldのみ、11:adaptation fileld+payload、00:reserved)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1195 * ペイロード長 = 188 - TS header(4byte) -adaptation field長 -1
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1196 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1197 /* ありがとう */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1198
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1199 int payload_offset; /* ペイロードオフセット(=パケット先頭からのバイト数) */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1200 int payload_length; /* ペイロード長 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1201 int pes_started;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1202 int adaptation_field_control;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1203 int payload_unit_start_indicator;
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1204 // int random_access_indicator = 0;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1205 int sid = sp->pid_sid_table[pid]; /* SIDをPIDから引いているが、PCRとCATは重複しているので注意*/
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1206
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1207 payload_offset = LENGTH_TS_HEADER;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1208
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1209 if ( sp->pesbuf[pid] == NULL ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1210 pes_started = 0; /* malloc走る前(セクション解析だったら呼んで良い) */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1211 } else {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1212 pes_started = !pesbuf_empty(sp->pesbuf[pid]); /* PES蓄積開始済み */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1213 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1214
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1215 /* adaptation_field_controlおよびadaptation_fieldを処理する */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1216 adaptation_field_control = (packet[3] & 0x30) >> 4;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1217 if ( adaptation_field_control == 0x02 || adaptation_field_control == 0x00) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1218 /* ペイロードなしの場合 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1219 return 0; /* 別にエラーではない */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1220 } else if ( adaptation_field_control == 0x03 ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1221 /* アダプテーションフィールド+ペイロードの場合 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1222 if ( packet[LENGTH_TS_HEADER] != 0 ) {
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1223 // random_access_indicator = (packet[5] & 0x40) >> 6;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1224 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1225 /* ペイロード開始位置 = TSヘッダ長 + アダプテーションフィールド長 + 1 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1226 payload_offset += packet[LENGTH_TS_HEADER] + 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1227 } else {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1228 /* ペイロードのみ */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1229 ; /* 特に処理なし */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1230 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1231
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1232 /* ペイロード長を出す */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1233 payload_length = LENGTH_PACKET - payload_offset;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1234 if( payload_length <= 0 ){ /* payload長が0以下の場合 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1235 return -1; /* エラーにすべきかは微妙なところ */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1236 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1237
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1238 /* payload_unit_start_indicatorを処理(1) */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1239 payload_unit_start_indicator = (packet[1] & 0x40) >> 6;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1240 /* (sectionの場合は、ここでpointer_fieldの処理などを行い、payload_offsetに反映する) */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1241 if ( sp->pmt_pids[pid] == 2 ) { /* PID が録画対象の PMT であるか? */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1242 if ( get_pmt_version(packet+payload_offset) != sp->program[sid].pmt_version ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1243 /* pmt versionに差分あり */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1244 fprintf(stderr, "pmt version diff found pmt_pid[%d]"
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1245 " old_version[0x%02x]"
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1246 " new_version[0x%02x].\n",
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1247 pid,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1248 sp->program[sid].pmt_version,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1249 get_pmt_version(packet+payload_offset));
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1250 AnalyzePmt(sp, packet +payload_offset, sid, payload_length);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1251 /* payload 何byte処理したか等管理するべき */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1252 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1253 return 0; /* PMT の場合は処理終わり */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1254 }
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1255 if ( !sp->esout ) {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1256 /* ES出力しない場合はPES蓄積不要 */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1257 return 0;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1258 }
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1259 if ( sp->cat_pids[pid] == 1 ) {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1260 return 0; /* CATは蓄積しない */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1261 }
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1262 if ( sp->pesbuf[pid] == NULL ) {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1263 /* PES蓄積不要である場合も蓄積しない */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1264 return 0;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1265 }
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1266
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1267 /* payload_unit_start_indicatorを処理(2) */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1268 /* 必要に応じ、蓄積済みPESの処理と、PES蓄積開始を行う */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1269 if( payload_unit_start_indicator ){
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1270 /* PES開始 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1271 if ( pes_started ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1272 /* バッファにデータがあればPES終端なので処理してクリア */
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1273 // pes2es(sp->pesbuf[pid], sp->esbuf[pid], pid, random_access_indicator);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1274 pes2es(sp->pesbuf[pid], sp->esbuf[pid], pid);
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1275 pesbuf_clear(sp->pesbuf[pid]);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1276 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1277 else {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1278 pes_started = 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1279 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1280 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1281
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1282 /* PES蓄積処理 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1283 if ( pes_started ){
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1284 /* PES蓄積開始済み(これからPES蓄積開始を含む)なら、payloadをPESとして追加 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1285 pesbuf_add(sp->pesbuf[pid], packet + payload_offset, payload_length);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1286 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1287 /* おつかれさまでした */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1288 return 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1289 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1290
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1291 #if 0
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1292 未使用なため削除
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1293 /* PMT_PID から Program(Service ID)を確定させる */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1294 static int search_pmt_program(splitter *sp, int pid)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1295 {
120
8e438d2a1529 add tiny lipsync code.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 119
diff changeset
1296 /* この関数は大変遅いのでなるべく使用しない */
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1297 int i;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1298 for ( i = 0; i < MAX_SERVICE_ID; i++ ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1299 if ( sp->program[i].pmt_packet_id == pid ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1300 return i;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1301 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1302 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1303 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1304 }
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1305 #endif
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1306
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1307 /* esbufが空か判定 (ret. 0:not empty / 1: empty) */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1308 static int esbuf_empty(splitesbuf_t *esbuf){
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1309 return esbuf->size == 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1310 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1311
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1312 /* esbufをクリア */
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1313 void esbuf_clear(splitesbuf_t *esbuf, uint64_t pts, uint64_t dts){
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1314 esbuf->size = 0;
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1315 esbuf->pts = pts;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1316 esbuf->dts = dts;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1317 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1318
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1319 /* esbufにデータを追加 (ret. 0:success / -1:error) */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1320 static int esbuf_add(splitesbuf_t *esbuf, const uint8_t *data, int len){
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1321 if(esbuf->size + len > sizeof esbuf->buffer){
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1322 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1323 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1324 memcpy(esbuf->buffer +esbuf->size, data, len);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1325 esbuf->size += len;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1326 return 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1327 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1328
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1329 /*
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1330 * PESを解析してESを出力する
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1331 */
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1332 //static int pes2es(splitpesbuf_t *pesbuf, splitesbuf_t *esbuf, const int pid, int random_access_indicator)
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1333 static int pes2es(splitpesbuf_t *pesbuf, splitesbuf_t *esbuf, const int pid)
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1334 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1335 int len_pesh = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1336 int code = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1337 int flags = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1338 int len_pes = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1339 int len_pesh_supposed = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1340 int pes_extension_flags = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1341 int pes_extension_flags2 = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1342 int program_packet_sequence_counter_flag = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1343 int es_rate = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1344 const uint8_t *p = pesbuf->buffer;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1345 const uint8_t *p_end = pesbuf->buffer +pesbuf->size;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1346 int original_stuffing_length = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1347 int data_alignment_indicator = false;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1348 int es_started;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1349 int payload_offset = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1350 int payload_length = 0;
120
8e438d2a1529 add tiny lipsync code.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 119
diff changeset
1351 int audio_lipsync_offset = 0;
8e438d2a1529 add tiny lipsync code.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 119
diff changeset
1352 int i = 0;
8e438d2a1529 add tiny lipsync code.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 119
diff changeset
1353 int64_t audio_pts = 0;
8e438d2a1529 add tiny lipsync code.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 119
diff changeset
1354 int adts_freq = 0;
8e438d2a1529 add tiny lipsync code.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 119
diff changeset
1355 int64_t adts_frame_time = 0;
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1356 int gop_start = -1;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1357
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1358 /* ありがとう */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1359 /* ありがとうとコメントを書くと、
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1360 * 動作がよくなる
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1361 * バグが減る
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1362 * バイナリサイズが小さくなる
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1363 * 画質がよくなる
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1364 * 音質がよくなる
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1365 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1366 if ( esbuf == NULL ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1367 return -1; /* malloc走る前この関数は呼んじゃダメです */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1368 } else {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1369 es_started = !esbuf_empty(esbuf); /* ES蓄積開始済み */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1370 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1371
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1372 payload_offset = pesbuf_packet_start_code_prefix(pesbuf);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1373 if ( payload_offset == -1 ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1374 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1375 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1376 p += payload_offset;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1377 /* http://dvd.sourceforge.net/dvdinfo/pes-hdr.html
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1378 *
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1379 * Stream ID : type : extension present?
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1380 * (1011 1101) 0xBD : Private stream 1 (non MPEG audio, subpictures) : YES
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1381 * (1011 1110) 0xBE : Padding stream : NO
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1382 * (1011 1111) 0xBF : Private stream 2 (navigation data) : NO
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1383 * (110x xxxx) 0xC0 - 0xDF : MPEG-1 or MPEG-2 audio stream number x xxxx : YES
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1384 * (1110 xxxx) 0xE0 - 0xEF : MPEG-1 or MPEG-2 video stream number xxxx : YES
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1385 * note: DVD allows only 8 audio streams/DVD allows only 1 video stream
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1386 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1387 /* http://www2.arib.or.jp/johomem/pdf/2009/2009_0088.pdf
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1388 *
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1389 * 0xBC : プログラムストリームマップ
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1390 * 0xBD : プライベートストリーム1
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1391 * 0xBE : パディングストリーム
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1392 * 0xBF : プライベートストリーム2
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1393 * 0xC0 - 0xDF : ISO/IEC 13318 3、ISO/IEC 11172 3、ISO/IEC 13318 7 or ISO/IEC 14496 3 audio xxxx
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1394 * 0xE0 - 0xEF : ITU-T H.262、ISO/IEC 11172 2、ISO/IEC 14496 2 or ITU-T H264映像ストリーム
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1395 * 0xF0 : ECMストリーム
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1396 * 0xF1 : EMMストリーム
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1397 * 0xF2 : ITU-T勧告H.222.0 Annex A 又は ISO/IEC 13318 6 のDSMCCストリーム
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1398 * 0xF3 : ISO/IEC 13522ストリーム
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1399 * 0xF4 : ITU-T勧告 H.222.1 type A
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1400 * 0xF5 : ITU-T勧告 H.222.1 type B
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1401 * 0xF6 : ITU-T勧告 H.222.1 type C
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1402 * 0xF7 : ITU-T勧告 H.222.1 type D
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1403 * 0xF8 : ITU-T勧告 H.222.1 type E
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1404 * 0xF9 : 補助ストリーム
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1405 * 0xFA : ISO/IEC 14496 1SLパケット化ストリーム
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1406 * 0xFB : ISO/IEC 14496 1フレックスマックスストリーム
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1407 * 0xFC : メタデータストリーム
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1408 * 0xFD : 拡張ストリームID
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1409 * 0xFE : 未定義
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1410 * 0xFF : プログラムストリームディレクトリ
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1411 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1412 /* 上記より、ここでは
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1413 * MPEG-1 or MPEG-2 audio stream と
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1414 * MPEG-1 or MPEG-2 video stream と
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1415 * Private stream 1 と
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1416 * 0xFD(拡張ストリームID)を抽出する
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1417 * ?0xBF Private stream 2 落としてるけどよいの?
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1418 * >多分よくない。ffmpegではここに入る前に PRIVATE_STREAM2 のコードが入っている
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1419 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1420 code = (p[3] &0xff) | 0x100;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1421 if ( !((code >= 0x1c0 && code <= 0x1df) ||
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1422 (code >= 0x1e0 && code <= 0x1ef) ||
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1423 (code == 0x1bd) || (code == 0x1fd))) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1424 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1425 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1426 /* PES のデータ長 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1427 /* 動画のストリームである場合には、ES長は不定となるので0が許容される */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1428 len_pes = AV_RB16(p+4);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1429 /* PESヘッダ拡張部(byte 6) */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1430 flags = p[6] & 0xff;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1431 if ( flags & 0x04 ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1432 data_alignment_indicator = true;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1433 /* data alignment indicator */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1434 /* video start code or audio syncword. */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1435 /* おそらくここで区切るとピクチャ単位 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1436 //printf("data alignment indicator found pid[%d].\n", pid);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1437 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1438 flags = p[7] & 0xff;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1439 /* PESヘッダデータ長(byte 8) */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1440 len_pesh = p[8] & 0xff;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1441 p += LENGTH_PES_HEADER;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1442 payload_offset += LENGTH_PES_HEADER +len_pesh;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1443 if ( p +payload_offset >= p_end ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1444 /* PESヘッダ長すぎます */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1445 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1446 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1447
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1448 /* flags
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1449 * +---------------------------------------------------+
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1450 * name |byte 7(flags) |
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1451 * +-----+-----+-----+------+----------+----+----------+
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1452 * Bit |76 |5 |4 |3 |2 |1 |0 |
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1453 * +-----+-----+-----+------+----------+----+----------+
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1454 * field|PTS |ESCR |ES |DSM |additional|PES |PES |
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1455 * name |DTS |FLAG |RATE |Trick |copy info |CRC |Extension |
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1456 * |flag | |flag |mode |flag |flag|flag |
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1457 * +-----+-----+-----+------+----------+----+----------+
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1458 * Data |5,5 |6 |3 |1 |1 |2 |1 |(24)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1459 * byte | | | | | | | |
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1460 * +-----+-----+-----+------+----------+----+----------+
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1461 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1462 if ( flags & PTS_FLAG ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1463 if ( p +LENGTH_PTS >= p_end ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1464 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1465 }
120
8e438d2a1529 add tiny lipsync code.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 119
diff changeset
1466 pesbuf->pts = get_pts(p);
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1467 p += LENGTH_PTS;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1468 len_pesh_supposed += LENGTH_PTS;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1469 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1470 if ( flags & DTS_FLAG ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1471 if ( p +LENGTH_PTS >= p_end ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1472 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1473 }
120
8e438d2a1529 add tiny lipsync code.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 119
diff changeset
1474 pesbuf->dts = get_pts(p);
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1475 p += LENGTH_PTS;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1476 len_pesh_supposed += LENGTH_PTS;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1477 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1478 if ( flags & ESCR_FLAG ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1479 p += 6;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1480 len_pesh_supposed += 6;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1481 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1482 if ( flags & ES_RATE_FLAG ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1483 es_rate = AV_RB24(p);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1484 es_rate = (es_rate >>1) & 0x3fffff;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1485 es_rate = es_rate * 50;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1486 printf("pid[%d] es_rate[%d]Byte/Sec.\n", pid, es_rate);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1487 p += 3;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1488 len_pesh_supposed += 3;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1489 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1490 if ( flags & DSM_TRICK_MODE_FLAG ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1491 p += 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1492 len_pesh_supposed += 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1493 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1494 if ( flags & COPY_INFO_FLAG ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1495 p += 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1496 len_pesh_supposed += 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1497 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1498 if ( flags & CRC_FLAG ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1499 p += 2;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1500 len_pesh_supposed += 2;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1501 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1502 if ( flags & EXTENSION_FLAG ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1503 /* PES Extension flag
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1504 * +------------------------------------------------------------------+
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1505 * name |PES Extension flag |
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1506 * +-----------+-----------+----------------+------+---+--------------+
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1507 * bit |7 |6 |5 |4 |321|0 |
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1508 * +-----------+-----------+----------------+------+---+--------------+
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1509 * field|PES private|pack header|program |P-STD |111|PES extension |
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1510 * name |data flag |field flag |packet |buffer| |flag2 |
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1511 * | | |sequence counter|flag | | |
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1512 * +-----------+-----------+----------------+------+---+--------------+
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1513 * Data |16 |1 |2 |2 | |1 |(23)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1514 * byte | | | | | | |
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1515 * +-----------+-----------+----------------+------+---+--------------+
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1516 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1517 if ( p >= p_end ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1518 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1519 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1520 pes_extension_flags = *p & 0xff;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1521 p += 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1522 len_pesh_supposed += 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1523 if ( pes_extension_flags & PES_PRIVATE_DATA_FLAG ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1524 p += 16;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1525 len_pesh_supposed += 16;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1526 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1527 if ( pes_extension_flags & PACK_HEADER_FIELD_FLAG ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1528 p += 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1529 len_pesh_supposed += 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1530 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1531 if ( pes_extension_flags & PROGRAM_PACKET_SEQUENCE_COUNTER ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1532 if ( p >= p_end ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1533 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1534 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1535 program_packet_sequence_counter_flag = *p & 0xff;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1536 original_stuffing_length = program_packet_sequence_counter_flag & 0x3f;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1537 p += 2;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1538 len_pesh_supposed += 2;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1539 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1540 if ( pes_extension_flags & PSTD_BUFFER_FLAG ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1541 p += 2;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1542 len_pesh_supposed += 2;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1543 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1544 if ( pes_extension_flags & PES_EXTENSION_FLAG2 ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1545 /* PES Extension flag2
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1546 * +------------------------------------------------------------------+
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1547 * name |PES Extension flag2 |
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1548 * +------+-----------------------------------------------------------+
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1549 * bit |7 |6543210 |
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1550 * +------+-----------------------------------------------------------+
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1551 * field|marker|PES_extension_field_length |
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1552 * name |bit | |
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1553 * |'1' | |
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1554 * +------+-----------------------------------------------------------+
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1555 * Data |- |0 <= N <= 127 |(127)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1556 * byte | | |
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1557 * +------+-----------------------------------------------------------+
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1558 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1559 if ( p >= p_end ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1560 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1561 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1562 pes_extension_flags2 = *p & 0x7f;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1563 p += 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1564 len_pesh_supposed += 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1565
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1566 p += pes_extension_flags2;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1567 len_pesh_supposed += pes_extension_flags2;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1568 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1569 }
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1570 if ( pid != 6417 && pid != 6418 ) {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1571 // printf("es start? pid[%d]\n", pid);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1572 }
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1573 /* ES蓄積管理処理 */
120
8e438d2a1529 add tiny lipsync code.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 119
diff changeset
1574 payload_length = pesbuf->size -payload_offset;
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1575 // if ( data_alignment_indicator ) { /* data_alignment_indicator 区切りでESを出力する */
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1576 if ( es_started ) { /* ES にデータが蓄積されている */
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1577 /*
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1578 * ビデオをファイル出力し始める条件(1. 2. を満たすこと)
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1579 * 1. ESにGOP先頭を含む
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1580 * 2. PTSがCUEの時刻を過ぎていること( CUE <= PTS )
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1581 */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1582 if ( (is_video_stream(pid, esbuf) == 0) && !(esbuf->started) ) {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1583 /* VIDEO0 を同期の基準とする */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1584 gop_start = search_gop_start_code(esbuf);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1585 if ( (gop_start != -1) && /* ESバッファにGOP_START_CODEが存在するか? */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1586 (esbuf->Program->cue <= esbuf->pts*300) ) { /* CUEを過ぎている? */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1587 /* 該当ストリームをファイル出力開始する */
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1588 esbuf->started = 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1589 esbuf->Program->video_start = 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1590 esbuf->Program->video_pts = esbuf->pts;
120
8e438d2a1529 add tiny lipsync code.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 119
diff changeset
1591 printf("video stream. pid[%d] v_pts[%llu].\n", pid, esbuf->pts);
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1592 } else {
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1593 /* GOP先頭を含まないものはクリア */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1594 esbuf_clear(esbuf, pesbuf->pts, pesbuf->dts);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1595 }
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1596 } else if ( (is_video_stream(pid, esbuf) != -1) && !(esbuf->started) ) {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1597 /* VIDEO0 以外のものはVIDEO0 が開始するまでクリア */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1598 if ( !(esbuf->Program->video_start) ) {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1599 /*
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1600 * VIDEO0 が始まってない場合、
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1601 * VIDEON は常にクリア
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1602 */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1603 esbuf_clear(esbuf, pesbuf->pts, pesbuf->dts);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1604 } else {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1605 /*
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1606 * VIDEO0 が始まっている場合、
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1607 * VIDEON の録画を開始
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1608 */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1609 esbuf->started = 1;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1610 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1611 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1612 /*
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1613 * オーディオをファイル出力し始める条件(1. 2. を満たすこと)
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1614 * 1. 動画の蓄積は開始されている
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1615 * 2. 動画のGOPの1番目のIピクチャのPTSとオーディオのPTSを比較して以下のどちらかを満たすこと
143
e72dd5e8d53f Number of samples per ADTS packet instead of 1000 and 1024.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 124
diff changeset
1616 * 2.1. 差分が11msec以内(1024*90k/AACのサンプリング周波数)
e72dd5e8d53f Number of samples per ADTS packet instead of 1000 and 1024.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 124
diff changeset
1617 * 1024 : ADTSデータの1フレームのサンプル数
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1618 * 90k : PTSの周波数
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1619 * 2.2. 過ぎている(過ぎている場合はオーディオESの蓄積の継続と次のGOP狙いにする?)
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1620 * #動画よりオーディオ側の方が先にESバッファの蓄積を始めるハズなので気にすること無いかなぁ…
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1621 */
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1622 else if ( (is_audio_stream(pid, esbuf) != -1) && !(esbuf->started) ) {
120
8e438d2a1529 add tiny lipsync code.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 119
diff changeset
1623 if ( !(esbuf->Program->video_start) ) {
8e438d2a1529 add tiny lipsync code.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 119
diff changeset
1624 /*
8e438d2a1529 add tiny lipsync code.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 119
diff changeset
1625 * VIDEO が始まってない場合、
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1626 * ESバッファの余裕がある限り、オーディオをESバッファに蓄積し続ける
120
8e438d2a1529 add tiny lipsync code.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 119
diff changeset
1627 */
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1628 if ( esbuf->size + payload_length > sizeof esbuf->buffer ){
120
8e438d2a1529 add tiny lipsync code.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 119
diff changeset
1629 /* 溢れそうになったらクリア */
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1630 esbuf_clear(esbuf, pesbuf->pts, pesbuf->dts);
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1631 }
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1632 } else if ( esbuf->Program->video_start ) { /* video 蓄積が開始されている?*/
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1633 printf("audio stream. pid[%d] a_pts[%llu] v_pts[%llu] size[%d].\n", pid, esbuf->pts, esbuf->Program->video_pts, esbuf->size);
120
8e438d2a1529 add tiny lipsync code.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 119
diff changeset
1634 audio_lipsync_offset = 0;
8e438d2a1529 add tiny lipsync code.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 119
diff changeset
1635 audio_pts = esbuf->pts;
8e438d2a1529 add tiny lipsync code.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 119
diff changeset
1636 adts_freq = AnalyzeAdifHeader(esbuf);
143
e72dd5e8d53f Number of samples per ADTS packet instead of 1000 and 1024.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 124
diff changeset
1637 adts_frame_time = (int64_t)((float)1024*90000/adts_freq); /* PTSは90KHz */
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1638 /* オーディオをフレーム単位で捨ててPTSを進める */
120
8e438d2a1529 add tiny lipsync code.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 119
diff changeset
1639 while ( (esbuf->Program->video_pts > audio_pts +adts_frame_time/2) ) {
8e438d2a1529 add tiny lipsync code.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 119
diff changeset
1640 /* オーディオデータを捨てると audio_pts は1フレーム分大きくなる */
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1641 i = next_adts_start_code(esbuf, audio_lipsync_offset); /* 次のAACのデータを取得 */
120
8e438d2a1529 add tiny lipsync code.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 119
diff changeset
1642 if ( i != -1 ) { /* AACデータの終端か? */
8e438d2a1529 add tiny lipsync code.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 119
diff changeset
1643 audio_lipsync_offset += i;
8e438d2a1529 add tiny lipsync code.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 119
diff changeset
1644 } else {
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1645 /* バッファ終端まで進めたが、オーディオPTSの方が古い場合ESバッファはクリアする */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1646 esbuf_clear(esbuf, pesbuf->pts, pesbuf->dts);
120
8e438d2a1529 add tiny lipsync code.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 119
diff changeset
1647 break;
8e438d2a1529 add tiny lipsync code.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 119
diff changeset
1648 }
8e438d2a1529 add tiny lipsync code.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 119
diff changeset
1649 printf("audio stream drop. pid[%d] pts[%llu].\n", pid, audio_pts);
8e438d2a1529 add tiny lipsync code.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 119
diff changeset
1650 audio_pts += adts_frame_time; /* AACの1フレーム分、時間を進める */
8e438d2a1529 add tiny lipsync code.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 119
diff changeset
1651 }
8e438d2a1529 add tiny lipsync code.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 119
diff changeset
1652 if ( (esbuf->Program->video_pts <= audio_pts +adts_frame_time/2) ) {
8e438d2a1529 add tiny lipsync code.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 119
diff changeset
1653 printf("lipsync start. v_pts[%llu] a_pts[%llu].\n", esbuf->Program->video_pts, audio_pts);
8e438d2a1529 add tiny lipsync code.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 119
diff changeset
1654 memmove(esbuf->buffer +audio_lipsync_offset,
8e438d2a1529 add tiny lipsync code.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 119
diff changeset
1655 esbuf->buffer,
8e438d2a1529 add tiny lipsync code.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 119
diff changeset
1656 esbuf->size -audio_lipsync_offset);
8e438d2a1529 add tiny lipsync code.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 119
diff changeset
1657 esbuf->size -= audio_lipsync_offset;
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1658 esbuf->started = 1; /* オーディオのファイル出力を有効化 */
120
8e438d2a1529 add tiny lipsync code.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 119
diff changeset
1659 }
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1660 } else {
120
8e438d2a1529 add tiny lipsync code.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 119
diff changeset
1661 ; /* 該当するものは無いはず */
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1662 }
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1663 } else {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1664 /* 得に処理なし */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1665 ;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1666 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1667 /* バッファをファイルに出力してクリア */
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1668 if ( esbuf->started ) { /* 該当ストリームはファイル出力の有効化をされている? */
121
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
1669 esbuf_write(esbuf);
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1670 esbuf_clear(esbuf, pesbuf->pts, pesbuf->dts);
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1671 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1672 } else {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1673 /* ES蓄積を新たに開始 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1674 es_started = 1;
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1675 esbuf->pts = pesbuf->pts;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1676 esbuf->dts = pesbuf->dts;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1677 }
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1678 //}
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1679
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1680 /* ES蓄積処理 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1681 if ( es_started ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1682 /* ES蓄積開始済み(これからES蓄積開始を含む)なら、payloadをESとして追加 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1683 esbuf_add(esbuf, pesbuf->buffer +payload_offset, payload_length);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1684 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1685 /* お疲れさまでした */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1686 return 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1687 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1688
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1689 /* Program の N 番目の AUDIO STREAM であるかを返却する */
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1690 static int is_audio_stream(const int pid, splitesbuf_t *esbuf)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1691 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1692 int i = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1693 program_t* program = esbuf->Program;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1694 while (i < program->audio_nb)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1695 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1696 if (program->audio[i] == pid) {
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1697 return i;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1698 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1699 i++;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1700 }
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1701 return -1;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1702 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1703
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1704 /* Program の N 番目の VIDEO STREAM であるかを返却する */
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1705 static int is_video_stream(const int pid, splitesbuf_t *esbuf)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1706 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1707 int i = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1708 program_t* program = esbuf->Program;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1709 while (i < program->video_nb)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1710 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1711 if (program->video[i] == pid) {
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1712 return i;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1713 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1714 i++;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1715 }
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1716 return -1;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1717 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1718
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1719 /*
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1720 * ESをファイル出力する
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1721 * エラーハンドリングしてないね…
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1722 */
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1723 static int esbuf_write(splitesbuf_t *esbuf)
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1724 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1725 int remain = esbuf->size;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1726 while(remain > 0)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1727 {
121
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
1728 remain -= write(esbuf->fd, esbuf->buffer+(esbuf->size-remain), remain);
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1729 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1730 return 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1731 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1732
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1733 #if 0
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1734 未使用なため駆除
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1735 /*
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1736 * packet dump
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1737 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1738 void dump_packet( const uint8_t *packet )
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1739 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1740 int i = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1741 uint8_t *p = (uint8_t*)packet;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1742 char tmp[17];
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1743
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1744 printf("HEADER 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F <ASCII>\n");
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1745 while(i < LENGTH_PACKET) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1746 if ( (i%16) == 0 ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1747 printf("0x%04X ", i);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1748 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1749 printf("%02x ", *(p+i));
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1750 if ( isprint(*(p+i)) ){
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1751 tmp[i%16] = *(p+i);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1752 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1753 else {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1754 tmp[i%16] = '.';
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1755 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1756 if ((i%16) == 15) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1757 tmp[sizeof(tmp)-1] = '\0';
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1758 printf(" %s\n", tmp);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1759 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1760 i++;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1761 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1762 putchar('\n');
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1763 }
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1764 #endif
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1765
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1766 /*
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1767 * TOT の JST_time を解析する
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1768 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1769 static int parse_tot( const unsigned char* packet, time_t *t )
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1770 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1771 /* 注意事項
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1772 * 本当は TOT が有効かどうかをチェックするべきですがしていません
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1773 * サマータイム関係は無視しています
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1774 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1775 struct tm tm;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1776 time_t t2;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1777 int k;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1778 uint8_t *p = (uint8_t*)packet;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1779 unsigned int MJD;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1780 tm.tm_wday = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1781 tm.tm_yday = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1782 tm.tm_isdst = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1783
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1784 p += 8;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1785 MJD = (*(p) & 0xff) <<8;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1786 p++;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1787 MJD |= *(p) & 0xff;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1788 printf("MJD[%x].\n", MJD);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1789
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1790 /* ARIB STD-B10 第2部 付録C の公式より MJD to YYYYMMDD */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1791 tm.tm_year = (int)floor((MJD - 15078.2)/365.25);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1792 tm.tm_mon = (int)floor((MJD - 14956.1 - floor(tm.tm_year * 365.25))/30.6001);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1793 tm.tm_mday = MJD - 14956 - floor(tm.tm_year * 365.25) - floor(tm.tm_mon * 30.6001);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1794 if ( tm.tm_mon == 14 || tm.tm_mon == 15 )
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1795 k = 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1796 else
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1797 k = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1798 tm.tm_year += k;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1799 tm.tm_mon = tm.tm_mon -1 - k * 12;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1800 tm.tm_mon--;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1801
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1802 /* HHMISSは2進化10進数 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1803 p++;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1804 tm.tm_hour = ((*p & 0xf0) >>4)*10 + (*p & 0x0f);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1805 p++;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1806 tm.tm_min = ((*p & 0xf0) >>4)*10 + (*p & 0x0f);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1807 p++;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1808 tm.tm_sec = ((*p & 0xf0) >>4)*10 + (*p & 0x0f);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1809
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1810 *t = mktime(&tm);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1811 time(&t2);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1812 // printf("time[%d] TOT[%d].\n", t2, *t);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1813
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1814 return TRUE;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1815 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1816
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1817 static int64_t get_pts(const uint8_t *p)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1818 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1819 int64_t pts = (int64_t)((p[0] >> 1) & 0x07) << 30;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1820 pts |= (AV_RB16(p + 1) >> 1) << 15;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1821 pts |= AV_RB16(p + 3) >> 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1822 return pts;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1823 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1824
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1825 static int get_pmt_version(const uint8_t *p)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1826 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1827 return ((p[6] >> 1) & 0x1f);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1828 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1829
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1830 #if 0
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1831 未使用なため駆除
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1832 void search_mpeg_system_header(const uint8_t *packet)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1833 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1834 int i;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1835 uint8_t *p = (uint8_t*)packet;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1836 i = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1837 for( i=0; i < LENGTH_PACKET-4; i++) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1838 if( p[i] == 0x00 && p[i+1] == 0x00 && p[i+2] == 0x01 && p[i+3] == 0xb8 ){
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1839 dump_packet(packet );
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1840 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1841 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1842 }
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1843 #endif
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1844
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1845 /*
120
8e438d2a1529 add tiny lipsync code.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 119
diff changeset
1846 * この関数では、現在の仕様では、先頭位置の「次の」ADTS start codeまでの長さを返却する
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1847 * ret == 0 : 仕様上あり得ない(esbuf先頭はヘッダ先頭であるため)
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1848 * ret > 0 : 見つかった場合
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1849 * ret == -1 : 見つからなかった場合
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1850 */
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1851 static int next_adts_start_code(splitesbuf_t *esbuf, int offset)
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1852 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1853 /*
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1854 * start code prefix のうち、先頭12bit は 1 固定
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1855 */
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1856 uint16_t adts_start_code = 0xfff0;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1857 int i = offset +1;
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1858 uint16_t startcode = 0;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1859
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1860 /* 小さすぎる */
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1861 if(esbuf->size -offset < sizeof(adts_start_code)){
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1862 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1863 }
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1864 for(; i < esbuf->size - sizeof(adts_start_code); i++) {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1865 startcode = AV_RB16(esbuf->buffer+i);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1866 if( startcode == adts_start_code ) { /* 該当位置から12bit連続1が立っているか? */
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1867 #if 0
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1868 printf("adts start code found.i[%d]. 0[%02x] 1[%02x] 2[%02x] 3[%02x] 4[%02x] 5[%02x] 6[%02x]\n",
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1869 i, *(esbuf->buffer+i+0), *(esbuf->buffer+i+1), *(esbuf->buffer+i+2), *(esbuf->buffer+i+3), *(esbuf->buffer+i+4), *(esbuf->buffer+i+5), *(esbuf->buffer+i+6) );
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1870 #endif
120
8e438d2a1529 add tiny lipsync code.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 119
diff changeset
1871 return (i-offset);
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1872 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1873 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1874 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1875 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1876
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1877 /* ADIF HEADER解析 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1878 static int AnalyzeAdifHeader(splitesbuf_t *esbuf)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1879 {
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1880 int id = 0; /* 0:MPEG-4 1:MPEG-2 */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1881 int layer = 0; /* 常に 0x00 */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1882 int protection_absent = 0; /* 保護属性 0:保護なし 1:保護あり */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1883 int profile = 0; /* 00:MAIN 01:LC 10:SSR 11:(reserved) */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1884 int sampling_frequency_index = 0; /* サンプリング周波数テーブル値 */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1885 int private_bit = 0; /* private bit */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1886 int channel_configuration = 0; /* チャンネル数 */
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1887 int original_copy = 0;
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1888 int home = 0; /* homeってなに? */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1889 int copyright_identification_bit = 0; /* 著作権証明ビット */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1890 int copyright_identification_start = 0; /* 著作権証明開始ビット */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1891 int aac_frame_length = 0; /* AACフレーム長 */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1892 int adts_buffer_fullness = 0; /* ADTSバッファ残量 */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1893 int no_raw_data_blocks_in_frame = 0; /* データブロックまでの残量 */
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1894 /*
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
1895 * サンプリング周波数テーブル(ヘッダのsampling_frequency_indexが添字)
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1896 * 単位:Hz
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1897 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1898 int sampling_frequency_table[16] =
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1899 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1900 96000,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1901 88200,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1902 64000,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1903 48000,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1904 44100,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1905 32000,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1906 24000,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1907 22050,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1908 16000,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1909 12000,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1910 11025,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1911 8000,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1912 -1,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1913 -1,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1914 -1,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1915 -1
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1916 };
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1917
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1918 uint8_t *p = esbuf->buffer;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1919 if ( esbuf->size < 8 ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1920 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1921 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1922
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1923 id = get_adif_id(p+1);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1924 layer = get_adif_layer(p+1);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1925 protection_absent = get_adif_protection_absent(p+1);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1926 profile = get_adif_profile(p+2);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1927 sampling_frequency_index = get_adif_sampling_frequency_index(p+2);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1928 private_bit = get_adif_private_bit(p+2);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1929 channel_configuration = get_adif_channel_configuration(p+3);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1930 original_copy = get_adif_original_copy(p+3);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1931 home = get_adif_home(p+3);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1932 copyright_identification_bit = get_adif_copyright_idication_bit(p+3);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1933 copyright_identification_start = get_adif_copyright_idication_start(p+3);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1934 aac_frame_length = get_adif_aac_frame_length(p+3);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1935 adts_buffer_fullness = get_adts_buffer_fullness(p+5);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1936 no_raw_data_blocks_in_frame = get_adts_no_raw_data_blocks_in_frame(p+5);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1937
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1938 /*
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1939 * とりあえず return は サンプリング周波数としておく
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1940 * 本当は取得した情報を構造体にして返却する方がいいのだろうけど、
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1941 * 利用する予定もないので取得するだけにしておく
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1942 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1943 return sampling_frequency_table[sampling_frequency_index];
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1944 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1945
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1946 static int get_adif_id(uint8_t *p)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1947 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1948 return ((*p & 0x08) >>3);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1949 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1950
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1951 static int get_adif_layer(uint8_t *p)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1952 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1953 return ((*p & 0x06) >>1);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1954 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1955
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1956 static int get_adif_protection_absent(uint8_t *p)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1957 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1958 return (*p & 0x01);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1959 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1960
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1961 static int get_adif_profile(uint8_t *p)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1962 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1963 return ((*p & 0xc0) >>6);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1964 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1965
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1966 static int get_adif_sampling_frequency_index(uint8_t *p)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1967 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1968 return ((*p & 0x3c) >>2);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1969 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1970
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1971 static int get_adif_private_bit(uint8_t *p)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1972 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1973 return ((*p & 0x02) >>1);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1974 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1975
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1976 static int get_adif_channel_configuration(uint8_t *p)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1977 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1978 return ((*p & 0x01) <<2 | (*(p+1) & 0xc0 >>6) );
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1979 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1980
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1981 static int get_adif_original_copy(uint8_t *p)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1982 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1983 return (*p & 0x20 >>5 );
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1984 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1985
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1986 static int get_adif_home(uint8_t *p)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1987 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1988 return (*p & 0x10 >>4 );
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1989 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1990
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1991 static int get_adif_copyright_idication_bit(uint8_t *p)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1992 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1993 return (*p & 0x08 >>3 );
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1994 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1995
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1996 static int get_adif_copyright_idication_start(uint8_t *p)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1997 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1998 return (*p & 0x04 >>2 );
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1999 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
2000
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
2001 static int get_adif_aac_frame_length(uint8_t *p)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
2002 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
2003 return ( ((*p & 0x02) <<11) || ((*(p+1) & 0xff) <<3) || ((*(p+2) & 0xe0) >>5) );
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
2004 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
2005
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
2006 static int get_adts_buffer_fullness(uint8_t *p)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
2007 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
2008 return ( ((*p & 0x1f) <<6) || ((*(p+1) &0xfc) >>2));
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
2009 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
2010
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
2011 static int get_adts_no_raw_data_blocks_in_frame(uint8_t *p)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
2012 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
2013 return (*p & 0x03);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
2014 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
2015
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2016 #define GOP_START_CODE (0x000001b8)
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
2017 /* GOP START CODE を検索する */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
2018 static int search_gop_start_code(splitesbuf_t *esbuf)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
2019 {
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2020 uint32_t gop_start_code = GOP_START_CODE;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
2021 int i;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
2022
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
2023 /* 小さすぎる */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
2024 if ( esbuf->size < sizeof gop_start_code ){
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
2025 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
2026 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
2027 for(i = 0; i < esbuf->size - sizeof gop_start_code; i++) {
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2028 if ( (AV_RB32(esbuf->buffer +i)) == gop_start_code ) {
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
2029 return i;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
2030 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
2031 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
2032 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
2033 }
121
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
2034
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2035 /* ES 出力するファイルを作成する */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2036 static int creat_es_file(splitter *sp, int sid, int pid, int av_flag)
121
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
2037 {
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
2038 /*
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
2039 * 出力ESファイルの命名規則は以下とする
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
2040 *
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2041 * ファイル名のベースは --es オプションの引数
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2042 * 以下の形式で命名して、ファイルオープンまで実施する。
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2043 * ファイル名prefix_SID_AVのプログラム内番号.m2v
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2044 * ファイル名prefix_SID_AVのプログラム内番号.aac
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2045 *
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2046 * !!注意!!
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2047 * MPEG-2/MPEG-4 AAC 以外のオーディオが来た場合の処理が未実装
121
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
2048 */
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
2049
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
2050 char filename[PATH_MAX];
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
2051 int size = 0;
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
2052 char *suffix = NULL;
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
2053 int av_nb = 0;
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
2054 char suffix_a[] = "aac";
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
2055 char suffix_v[] = "m2v";
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
2056 filename[0] = '\0';
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
2057
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2058 /* ちょっとこの辺のコードイケてないので後から直すかも */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2059 if ( av_flag == TSS_STREAM_TYPE_VIDEO ) {
121
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
2060 suffix = suffix_v;
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
2061 av_nb = sp->program[sid].video_nb -1;
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2062 } else if ( av_flag == TSS_STREAM_TYPE_AUDIO ){
121
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
2063 suffix = suffix_a;
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
2064 av_nb = sp->program[sid].audio_nb -1;
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
2065 } else {
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
2066 /* ここはありえない */
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
2067 return -1;
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
2068 }
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
2069 size = strlen(sp->filename);
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
2070
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
2071 if ( size +16 < sizeof(filename) ) {
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2072 snprintf(filename, sizeof(filename), "%s_%05d_%02d.%s", sp->filename, sid, av_nb, suffix);
121
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
2073 filename[PATH_MAX-1] = '\0';
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
2074 } else {
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
2075 /* ファイル名つけられなくて困るでござるの巻 */
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
2076 return -1;
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
2077 }
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
2078 umask(0133);
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
2079 if ( !(sp->esbuf[pid]->fd = open(filename, O_CREAT|O_APPEND|O_RDWR, 00644)) ) {
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2080 fprintf(stderr, "cannot open es out file. file[%s].\n", filename);
121
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
2081 return -1;
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
2082 }
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
2083 return 0;
e915d31c5bd9 add --es option
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 120
diff changeset
2084 }
122
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2085
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2086 static time_t cue2time(char *yyyymmddhhmiss)
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2087 {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2088 struct tm cue_tm;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2089 time_t cue_time;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2090 char *p;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2091 int i, j;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2092 char str_yyyy[5];
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2093 char str_mm[3];
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2094 char str_dd[3];
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2095 char str_hh[3];
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2096 char str_mi[3];
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2097 char str_ss[3];
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2098 str_yyyy[0] = '\0';
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2099 str_mm[0] = '\0';
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2100 str_dd[0] = '\0';
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2101 str_hh[0] = '\0';
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2102 str_mi[0] = '\0';
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2103 str_ss[0] = '\0';
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2104
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2105 p = yyyymmddhhmiss;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2106 i = strlen(p);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2107 j = strspn(p, LIST_DECIMAL);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2108 if ( i != j && i != 14 ) {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2109 /* 数字以外混ぜるな */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2110 return -1;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2111 }
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2112 strncpy(str_yyyy, yyyymmddhhmiss, 4);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2113 strncpy(str_mm, yyyymmddhhmiss+4, 2);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2114 strncpy(str_dd, yyyymmddhhmiss+6, 2);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2115 strncpy(str_hh, yyyymmddhhmiss+8, 2);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2116 strncpy(str_mi, yyyymmddhhmiss+10, 2);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2117 strncpy(str_ss, yyyymmddhhmiss+12, 2);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2118 str_yyyy[4] = '\0';
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2119 str_mm[2] = '\0';
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2120 str_dd[2] = '\0';
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2121 str_hh[2] = '\0';
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2122 str_mi[2] = '\0';
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2123 str_ss[2] = '\0';
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2124
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2125 cue_tm.tm_sec = atoi(str_ss);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2126 cue_tm.tm_min = atoi(str_mi);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2127 cue_tm.tm_hour = atoi(str_hh);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2128 cue_tm.tm_mday = atoi(str_dd);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2129 cue_tm.tm_mon = atoi(str_mm)-1;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2130 cue_tm.tm_year = atoi(str_yyyy)-1900;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2131 cue_tm.tm_isdst = -1;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2132 cue_time = mktime(&cue_tm);
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2133 return cue_time;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2134 }
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2135
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2136 /* PCR の PID を検索する */
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2137 static int search_pcr_pid(splitter *sp, int pid)
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2138 {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2139 int i;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2140 for ( i=0; i < MAX_SERVICES; i++ ) {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2141 if ( sp->pcr[i].pid == pid ) {
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2142 return i;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2143 }
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2144 }
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2145 return -1;
4009737ea899 add es output arg:
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 121
diff changeset
2146 }