annotate recpt1/tssplitter_lite.c @ 119:4e7aaa72e158

ES out early release version.
author Naoya OYAMA <naoya.oyama@gmail.com>
date Mon, 19 Apr 2010 00:30:09 +0900
parents ac39bb18136e
children 8e438d2a1529
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
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
6 Copyright 2010 Naoya OYAMA <naoya.oyama@gmail.com>
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"
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
33
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
34 #ifndef AV_RB32
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
35 #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
36 (((const uint8_t*)(x))[1] << 16) | \
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
37 (((const uint8_t*)(x))[2] << 8) | \
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
38 ((const uint8_t*)(x))[3])
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
39 #endif
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
40
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
41 #ifndef AV_RB24
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
42 #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
43 (((const uint8_t*)(x))[1] << 8) | \
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
44 ((const uint8_t*)(x))[2])
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
45 #endif
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
46
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
47 #ifndef AV_RB16
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
48 #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
49 #endif
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
50
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
51
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
52 /* prototypes */
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
53 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
54 static int AnalyzePat(splitter *sp, unsigned char *buf);
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
55 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
56 static char** AnalyzeSid(char *sid);
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
57 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
58 static int GetCrc32(unsigned char *data, int len);
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
59 static int GetPid(unsigned char *data);
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
60 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
61 void dump_packet( const uint8_t *packet );
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
62 static int parse_pcr(int64_t *ppcr_high, int *ppcr_low, const uint8_t *packet);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
63 //static int parse_pts(int64_t *ppts, int64_t *pdts, const uint8_t *packet, int *len_pes, splitesbuf_t *esbuf, const int pid);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
64 //static int ts2pes(int64_t *ppts, int64_t *pdts, const uint8_t *packet, splitpesbuf_t *pesbuf, splitesbuf_t *esbuf, const int pid);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
65 static int DemuxTs(const uint8_t *packet, splitter *sp, const int pid, int *random_access);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
66 static int pes2es(splitpesbuf_t *pesbuf, splitesbuf_t *esbuf, const int pid);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
67 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
68 void search_mpeg_system_header(const uint8_t *p);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
69 int esbuf_write(splitesbuf_t *esbuf, int pid);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
70 //void forward_stc(timespec *stc, timespec offset);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
71 //
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
72
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
73 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
74 static int pesbuf_empty(splitpesbuf_t *pesbuf);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
75 void pesbuf_clear(splitpesbuf_t *pesbuf);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
76 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
77 static int esbuf_empty(splitesbuf_t *esbuf);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
78 void esbuf_clear(splitesbuf_t *esbuf);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
79 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
80 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
81 static int esbuf_adts_start_code_prefix(splitesbuf_t *esbuf, int offset);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
82 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
83 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
84 static int AnalyzeAdifHeader(splitesbuf_t *esbuf);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
85 static int get_adif_id(uint8_t *p);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
86 static int get_adif_layer(uint8_t *p);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
87 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
88 static int get_adif_profile(uint8_t *p);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
89 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
90 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
91 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
92 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
93 static int get_adif_home(uint8_t *p);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
94 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
95 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
96 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
97 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
98 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
99 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
100 static int search_gop_start_code(splitesbuf_t *esbuf);
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
101
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
102 /**
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
103 * サービスID解析
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
104 */
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
105 static char** AnalyzeSid(
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
106 char* sid) // [in] サービスID(カンマ区切りテキスト)
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
107 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
108 int i = 0;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
109 char** sid_list = NULL;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
110 char* p;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
111 int CommaNum = 0;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
112
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
113 /* sid は次の形式の引数を許容する */
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 /* SID[0] */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
116 /* 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
117
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
118 /*カンマの数を数える*/
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
119 p = sid;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
120 while(*p != '\0')
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 if( *p == C_CHAR_COMMA ){
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
123 CommaNum++;
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 p++;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
126 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
127
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
128 /* sid_listの数はカンマの数+2(NULL止めするから) */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
129 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
130 if ( sid_list == NULL )
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 fprintf(stderr, "AnalyzeSid() malloc error.\n");
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
133 return NULL;
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
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
136 /* sidが空である場合 */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
137 p = sid;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
138 if ( strlen(p) == 0 )
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
139 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
140 sid_list[0] = NULL;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
141 return sid_list;
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
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
144 /* カンマ無し */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
145 if ( CommaNum == 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] = sid;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
148 sid_list[1] = NULL;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
149 return sid_list;
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 /* カンマ区切りで複数指定時 */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
153 i=0;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
154 p = sid;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
155 /* 文字列端に到達するか、カンマ数が数えた数に達したら終了 */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
156 while((*p != '\0') || i < CommaNum)
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 /* 現在の処理位置をsid_list[i]にセット */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
159 /* このタイミングの p は
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
160 * ・sid先頭
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
161 * ・[,]の次の文字
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
162 * いずれかであるので p を sid_list[i] に代入してよい
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
163 */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
164 sid_list[i] = p;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
165 i++;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
166
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
167 /* 最初に現れる[,]をNULL文字で置換する */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
168 p = strchr(p, C_CHAR_COMMA);
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
169 if ( p == NULL )
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 /* カンマが見つからない場合は最後の処理対象なので終了 */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
172 break;
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 *p = '\0';
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
175 /* 処理位置をNULLで置換した文字の次の位置に設定する */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
176 p++;
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 /* 最後のsid_list[n]はNULLポインタで止める */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
180 sid_list[i] = NULL;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
181
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
182 i=0;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
183 while( sid_list[i] != NULL )
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 i++;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
186 }
98
3fd15032fd3a tweak user interface for sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 96
diff changeset
187 #if 0
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
188 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
189 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
190 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
191 }
98
3fd15032fd3a tweak user interface for sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 96
diff changeset
192 #endif
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
193 return sid_list;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
194 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
195
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 * 初期化処理
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
198 */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
199 splitter* split_startup(
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
200 char *sid // [in] サービスID(引数で指定した文字列)
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 splitter* sp;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
204 int i;
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
205 sp = malloc(sizeof(splitter));
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
206 if ( sp == NULL )
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
207 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
208 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
209 return NULL;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
210 }
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
211 #define MAX_SERVICE_ID ( 0xffff )
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
212 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
213 if ( sp->program == NULL )
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
214 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
215 fprintf(stderr, "split_startup malloc error.\n");
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
216 return NULL;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
217 }
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
218 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
219 memset(sp->pmt_pids, 0, sizeof(sp->pmt_pids));
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
220
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
221 sp->sid_list = NULL;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
222 sp->pat = NULL;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
223 sp->sid_list = AnalyzeSid(sid);
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
224 if ( sp->sid_list == NULL )
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
225 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
226 free(sp);
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
227 return NULL;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
228 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
229 sp->pat_count = 0xFF;
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
230 sp->pmt_retain = -1;
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
231 sp->pmt_counter = 0;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
232 // sp->STC_timespec.tv_sec = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
233 // sp->STC_timespec.tv_nsec = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
234 // sp->tot_offset.tv_sec = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
235 // sp->tot_offset.tv_nsec = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
236 sp->cue_time = -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
237 sp->stc = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
238 sp->status = 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
239 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
240 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
241 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
242 for ( i=0; i < MAX_PID; i++ ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
243 /* pmt_version は (N%32) の値を取るので、0 で初期化してはならない */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
244 sp->program[i].pmt_version = -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
245 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
246 memset(sp->pid_sid_table, 0, sizeof(int)*MAX_PID);
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
247
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
248 return sp;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
249 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
250
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
251 /**
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
252 * 落とすPIDを確定させる
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
253 */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
254 int split_select(
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
255 splitter *sp, // [in/out] splitter構造体
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
256 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
257 )
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
258 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
259 int result;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
260 // TS解析
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
261 result = ReadTs(sp, sbuf);
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
262
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
263 return result;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
264 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
265
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
266 /**
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
267 * 終了処理
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
268 */
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
269 void split_shutdown(splitter* sp)
96
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 if ( sp != NULL ) {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
272 if ( sp->pat != NULL )
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 free(sp->pat);
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
275 sp->pat = NULL;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
276 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
277 if ( sp->sid_list != NULL )
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 free(sp->sid_list);
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
280 sp->sid_list = NULL;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
281 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
282 free(sp);
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
283 sp = NULL;
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 * TS 解析処理
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
289 *
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
290 * 対象のチャンネル番号のみの PAT の再構築と出力対象 PID の抽出を行う
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
291 */
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
292 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
293 {
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
294 #if 0
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
295 unsigned char **pat, // [out] PAT 情報(再構築後)
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
296 unsigned char* pids, // [out] 出力対象 PID 情報
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
297 char** sid_list, // [in] 出力対象サービス ID のリスト
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
298 unsigned char* pmt_pids, // [in] 出力対象PIDのPMT PID
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
299 , // [in] pt1_drvの入力TS
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
300 int* pmt_retain, // [in] PMTの落とすべき数
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
301 int* pmt_counter // [out] PMTの落とした数
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
302 #endif
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
303
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
304 int length = sbuf->size;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
305 int pid;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
306 int result = TSS_ERROR;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
307 int index;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
308
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
309 index = 0;
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
310 while(length - index - LENGTH_PACKET > 0) {
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
311 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
312 // PAT
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
313 if(PAT == pid) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
314 dump_packet(sbuf->data + index);
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
315 result = AnalyzePat(sp, sbuf->data + index);
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
316 if(TSS_SUCCESS != result) {
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
317 /* 下位の関数内部でmalloc error発生 */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
318 return result;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
319 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
320 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
321
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
322 // PMT
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
323 /* 残すpmt_pidである場合には、pmtに書かれている
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
324 * 残すべきPCR/AUDIO/VIDEO PIDを取得する */
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
325 if(sp->pmt_pids[pid] == 1) {
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
326 /*
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
327 * program(番組)とServiceID をベースに管理することにしているので、
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
328 * pmt_pidsとかもう必要ないかも…
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
329 */
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
330 /* この中にはPMT毎に一度しか入らないようにしておく */
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
331 int random_access;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
332 //AnalyzePmt(sp, sbuf->data + index, pid);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
333 //AnalyzePmt(sp, sbuf->data + index +4, pid, LENGTH_PACKET-4);
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
334 sp->pmt_pids[pid]++;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
335 sp->pmt_counter += 1;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
336 DemuxTs(sbuf->data +index, sp, pid, &random_access); /* AnalyzePmt より DemuxTs の方がアダプテーションフィールドの処理が良いので変更 */
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
337 }
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
338 /* 録画する全てのPMTについて、中にあるPCR/AUDIO/VIDEOのPIDを
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
339 * 得る */
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
340 /* pmt_counter と pmt_retain が一致する場合に条件は満たされる */
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
341 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
342 result = TSS_SUCCESS;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
343 break;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
344 }
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
345 else {
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
346 result = TSS_ERROR;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
347 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
348 index += LENGTH_PACKET;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
349 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
350
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
351 return(result);
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
352 }
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 * TS 分離処理
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
356 */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
357 int split_ts(
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
358 splitter *splitter, // [in] splitterパラメータ
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
359 ARIB_STD_B25_BUFFER *sbuf, // [in] 入力TS
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
360 splitbuf_t *dbuf // [out] 出力TS
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
361 )
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
362 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
363 int pid;
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
364 unsigned char *sptr, *dptr;
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
365 int s_offset = 0;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
366 int d_offset = 0;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
367 int64_t pcr;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
368 int64_t pcr_h;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
369 int pcr_l;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
370 struct timespec tot_timespec;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
371 struct timespec local_timespec;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
372 int len_pes;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
373 int random_access;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
374 int sid;
96
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 dbuf->size = 0;
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
378 if (sbuf->size < 0) {
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
379 return TSS_ERROR;
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
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
382 sptr = sbuf->data;
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
383 dptr = dbuf->buffer;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
384 #if 0
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
385 /* TOT受信済みであるなら、STC を成長させる */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
386 if ( sp->tot_offset.tv_nsec != 0 && sp->tot_offset.tv_sec != 0) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
387 forward_stc(&(sp->STC_timespec), sp->tot_offset);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
388 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
389 #endif
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
390
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
391 while(sbuf->size > s_offset) {
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
392 pid = GetPid(sptr + s_offset + 1);
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
393 sid = splitter->pid_sid_table[pid];
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
394 switch(pid) {
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
395
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
396 // PAT
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
397 case PAT:
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
398 // 巡回カウンタカウントアップ
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
399 if(0xFF == splitter->pat_count) {
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
400 splitter->pat_count = splitter->pat[3];
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
401 }
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
402 else {
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
403 splitter->pat_count = (splitter->pat_count + 1) % 16;
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
404 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
405 splitter->pat[3] = splitter->pat_count;
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 memcpy(dptr + d_offset, splitter->pat, LENGTH_PACKET);
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
408 d_offset += LENGTH_PACKET;
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
409 dbuf->size += LENGTH_PACKET;
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
410 break;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
411 case TOT:
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
412 /* TOT に TDTの情報全てが含まれており、実放送では TOT しか送信されない */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
413 /* TOT は 500msec の誤差が保証されている
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
414 * 閏秒の場合は最大1.5秒の誤差となる
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
415 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
416 #if 0
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
417 if ( sp->tot_offset.tv_nsec != 0 && sp->tot_offset.tv_sec != 0 ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
418 parse_tot(sptr + s_offset, &(tot_timespec.tv_sec));
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
419 clock_gettime(CLOCK_REALTIME, &local_timespec);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
420
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
421 /* TOT をSystem Time Clock(STC)に入れる */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
422 sp->STC_timespec.tv_sec = tot_timespec.tv_sec;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
423 sp->STC_timespec.tv_nsec = tot_timespec.tv_nsec;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
424
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
425 /* TOT と localtime の差分を sp->tot_offset に入れる */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
426 sp->tot_offset.tv_sec = tot_timespec.tv_sec - local_timespec.tv_sec;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
427 sp->tot_offset.tv_nsec = tot_timespec.tv_nsec - local_timespec.tv_nsec;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
428 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
429 #endif
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
430 /* STC が既にあるならTOT受信時に頭出し時刻を決定する */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
431 /* 59秒9990 あたりを頭出し時刻に設定でよいかな */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
432 if ( splitter->stc != 0 && splitter->cue_time == -1) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
433 /* TOT から cue_time を計算する */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
434 /* えいや。で、59秒9990固定決め打ち */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
435 parse_tot(sptr + s_offset, &(tot_timespec.tv_sec));
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
436 //cue_second = ((tot_timespec.tv_sec % 60) - 59);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
437 splitter->cue_time = splitter->stc + (((59 - (tot_timespec.tv_sec % 60))*(27*1000*1000)) + floor((27*1000*1000)*0.999));
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
438 //printf("stc[%lld]. cue_time[%lld].\n", splitter->stc, splitter->cue_time);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
439
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
440 } else {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
441 /* TOT受診時にSTCが存在しないならTOTは捨てる */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
442 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
443 break;
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
444 default:
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
445 /* 時間管理に関しての実装方針 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
446 /*
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
447 * 時間関係を扱っている変数のまとめ
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
448 * PCR : 42Bit @27MHz(プログラム毎に独立)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
449 * PTS : 42Bit @90KHz(SYSTEM ID(ES)毎に独立)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
450 * DTS : 42Bit @90KHz(SYSTEM ID(ES)毎に独立)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
451 * TOT : MJD + 2進化10進数(ストリームに一つだけ)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
452 * STC : 64Bit @27MHz(システムローカル時刻(ソースはTOT))
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
453 *
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
454 * STC と TOT の関連だけ計算出来るようにしておいて、
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
455 * 出力するようにする/しないの判定は全体的に、
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
456 * STCからTOTを使って出した時刻情報とする。かなぁ。
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
457 * PCR/PTS/DTSはオーバーフローしたときには34Bit目が立っていると見なすこと
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
458 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
459 // if ( 1 == splitter->pmt_pids[pid] ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
460 if ( 2 == splitter->pmt_pids[pid] ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
461 /* PMT の追跡 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
462 int random_access;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
463 DemuxTs((sptr+s_offset), splitter, pid, &random_access);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
464 }
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
465 /* pids[pid] が 1 は残すパケットなので書き込む */
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
466 if ( 1 == splitter->pids[pid] ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
467 len_pes = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
468 random_access = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
469 /* PCR 解析テスト */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
470 if (parse_pcr(&pcr_h, &pcr_l, (sptr+s_offset)) == 0){
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
471 pcr = pcr_h * 300 + pcr_l;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
472 /* PCR の種にするものは、Program の PCR として指定されたPacketIDのものとすること */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
473 /* STC は PCR を種にする */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
474 splitter->stc = pcr;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
475 // printf("PID[%d] pcr_h=[%llx] pcr_l=[%d] PCR[%f]\n",pid, pcr_h, pcr_l, ((double)pcr/(90000*300)));
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
476 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
477 /* TS処理 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
478 if (DemuxTs((sptr+s_offset), splitter, pid, &random_access) == 0 ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
479 #if 0
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
480 /* とりあえずやっつけ */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
481 /* パケットの画面表示時刻(pts) >= 録画開始時刻(cue_time) となった場合に録画開始 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
482 // if ( ((pts*300) >= splitter->cue_time) && (splitter->cue_time != -1)) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
483 if ( ((splitter->esbuf[pid].pts) >= splitter->program[sid].cue_time) && (splitter->program[sid].cue_time != -1)) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
484 splitter->cue_time = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
485 splitter->status = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
486 clock_gettime(CLOCK_REALTIME, &local_timespec);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
487 printf("start recording. time_sec[%d] nsec[%d].\n", local_timespec.tv_sec%60, local_timespec.tv_nsec);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
488 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
489 #endif
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
490 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
491 //search_mpeg_system_header(sptr+s_offset);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
492 /*
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
493 * STCが cue_time を経過したら録画開始
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
494 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
495 if ( splitter->cue_time != -1 && splitter->cue_time <= splitter->stc ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
496 memcpy(dptr + d_offset, sptr + s_offset, LENGTH_PACKET);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
497 d_offset += LENGTH_PACKET;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
498 dbuf->size += LENGTH_PACKET;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
499 if ( splitter->status ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
500 struct timespec local_timespec;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
501 clock_gettime(CLOCK_REALTIME, &local_timespec);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
502 printf("start recording. time_sec[%d] nsec[%d].\n", local_timespec.tv_sec%60, local_timespec.tv_nsec);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
503 splitter->status = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
504 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
505 }
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
506 }
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
507 break;
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
508 } /* switch */
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
509
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
510 s_offset += LENGTH_PACKET;
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
511 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
512
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
513 return(TSS_SUCCESS);
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
514 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
515
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
516 /**
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
517 * PAT 解析処理
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
518 *
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
519 * PAT を解析し、出力対象チャンネルが含まれているかチェックを行い、PAT を再構築する
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
520 */
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
521 static int AnalyzePat(splitter *sp, unsigned char *buf)
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
522 #if 0
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
523 unsigned char* buf, // [in] 読み込んだバッファ
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
524 unsigned char** pat, // [out] PAT 情報(再構築後)
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
525 unsigned char* pids, // [out] 出力対象 PID 情報
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
526 char** sid_list, // [in] 出力対象サービス ID のリスト
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
527 unsigned char* pmt_pids, // [out] サービス ID に対応する PMT の PID
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
528 int* pmt_retain // [out] 残すPMTの数
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
529 )
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
530 #endif
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
531 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
532 int pos[MAX_PID];
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
533 int service_id;
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
534 int i, j, k;
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
535 int size = 0;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
536 int pid;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
537 int result = TSS_SUCCESS;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
538 char **p;
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
539 int sid_found = FALSE;
98
3fd15032fd3a tweak user interface for sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 96
diff changeset
540 int avail_sids[MAX_SERVICES];
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
541
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
542 unsigned char *pat = sp->pat;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
543 unsigned char *pids = sp->pids;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
544 char **sid_list = sp->sid_list;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
545 unsigned char *pmt_pids = sp->pmt_pids;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
546
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
547 char chosen_sid[512];
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
548 chosen_sid[0] = '\0';
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
549
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
550 if(pat == NULL) {
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
551 /* 初期化 */
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
552 sp->pmt_retain = 0;
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
553 memset(pos, 0, sizeof(pos));
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
554 size = buf[7];
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
555
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
556 /* prescan SID/PMT */
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
557 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
558 avail_sids[j] = (buf[i] << 8) + buf[i+1];
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
559 sp->avail_pmts[j] = GetPid(&buf[i+2]);
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
560 }
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
561 sp->num_pmts = j;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
562
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
563 // 対象チャンネル判定
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
564 /* size + 8 = パケット全長 */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
565 /* 最終 4 バイトはCRCなので飛ばす */
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
566 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
567
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
568 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
569 p = sid_list;
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
570
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
571 while(*p) {
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
572 if(service_id == atoi(*p)) {
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
573 /* 録画対象の pmt_pids は 1 とする */
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
574 /* 録画対象の pmt の pids は 1 とする */
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
575 pid = GetPid(&buf[i + 2]);
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
576 *(pmt_pids+pid) = 1;
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
577 *(pids+pid) = 1;
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
578 pos[pid] = i;
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
579 sid_found = TRUE;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
580 sp->pmt_retain += 1;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
581 sp->program[service_id].pmt_packet_id = pid;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
582 sp->pid_sid_table[pid] = service_id;
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
583 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
584 p++;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
585 continue;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
586 }
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
587 else if(!strcasecmp(*p, "hd") || !strcasecmp(*p, "sd1")) {
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
588 /* hd/sd1 指定時には1番目のサービスを保存する */
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
589 if(service_id == avail_sids[0]) {
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
590 pid = GetPid(&buf[i + 2]);
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
591 *(pmt_pids+pid) = 1;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
592 *(pids+pid) = 1;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
593 pos[pid] = i;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
594 sid_found = TRUE;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
595 sp->pmt_retain += 1;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
596 sp->program[service_id].pmt_packet_id = pid;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
597 sp->pid_sid_table[pid] = service_id;
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
598 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
599 }
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
600 p++;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
601 continue;
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
602 }
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
603 else if(!strcasecmp(*p, "sd2")) {
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
604 /* sd2 指定時には2番目のサービスを保存する */
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
605 if(service_id == avail_sids[1]) {
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
606 pid = GetPid(&buf[i + 2]);
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
607 *(pmt_pids+pid) = 1;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
608 *(pids+pid) = 1;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
609 pos[pid] = i;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
610 sid_found = TRUE;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
611 sp->pmt_retain += 1;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
612 sp->program[service_id].pmt_packet_id = pid;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
613 sp->pid_sid_table[pid] = service_id;
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
614 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
615 }
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
616 p++;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
617 continue;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
618 }
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
619 else if(!strcasecmp(*p, "sd3")) {
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
620 /* sd3 指定時には3番目のサービスを保存する */
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
621 if(service_id == avail_sids[2]) {
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
622 pid = GetPid(&buf[i + 2]);
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
623 *(pmt_pids+pid) = 1;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
624 *(pids+pid) = 1;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
625 pos[pid] = i;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
626 sid_found = TRUE;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
627 sp->pmt_retain += 1;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
628 sp->program[service_id].pmt_packet_id = pid;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
629 sp->pid_sid_table[pid] = service_id;
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
630 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
631 }
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
632 p++;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
633 continue;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
634 }
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
635 else if(!strcasecmp(*p, "1seg")) {
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
636 /* 1seg 指定時には PMTPID=0x1FC8 のサービスを保存する */
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
637 pid = GetPid(&buf[i + 2]);
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
638 if(pid == 0x1FC8) {
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
639 *(pmt_pids+pid) = 1;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
640 *(pids+pid) = 1;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
641 pos[pid] = i;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
642 sid_found = TRUE;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
643 sp->pmt_retain += 1;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
644 sp->program[service_id].pmt_packet_id = pid;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
645 sp->pid_sid_table[pid] = service_id;
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
646 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
647 }
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
648 p++;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
649 continue;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
650 }
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
651 else if(!strcasecmp(*p, "all")) {
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
652 /* all指定時には全保存する */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
653 pid = GetPid(&buf[i + 2]);
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
654 *(pmt_pids+pid) = 1;
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
655 *(pids+pid) = 1;
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
656 pos[pid] = i;
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
657 sid_found = TRUE;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
658 sp->pmt_retain += 1;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
659 sp->program[service_id].pmt_packet_id = pid;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
660 sp->pid_sid_table[pid] = service_id;
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
661 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
662 break;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
663 }
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
664
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
665 p++;
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
666 } /* while */
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
667 }
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
668
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
669 /* 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
670 if(*sid_list && !sid_found) {
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
671 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
672 service_id = (buf[i] << 8) + buf[i+1];
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
673 pid = GetPid(&buf[i + 2]);
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
674 *(pmt_pids+pid) = 1;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
675 *(pids+pid) = 1;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
676 pos[pid] = i;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
677 sid_found = TRUE;
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
678 sp->pmt_retain += 1;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
679 sp->program[service_id].pmt_packet_id = pid;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
680 sp->pid_sid_table[pid] = service_id;
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
681 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
682 }
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
683 }
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
684
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
685 /* print SIDs */
98
3fd15032fd3a tweak user interface for sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 96
diff changeset
686 fprintf(stderr, "Available sid = ");
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
687 for(k=0; k < sp->num_pmts; k++)
98
3fd15032fd3a tweak user interface for sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 96
diff changeset
688 fprintf(stderr, "%d ", avail_sids[k]);
3fd15032fd3a tweak user interface for sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 96
diff changeset
689 fprintf(stderr, "\n");
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
690 fprintf(stderr, "Chosen sid =%s\n", chosen_sid);
98
3fd15032fd3a tweak user interface for sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 96
diff changeset
691
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
692 #if 0
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
693 /* print PMTs */
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
694 fprintf(stderr, "Available PMT = ");
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
695 for(k=0; k < sp->num_pmts; k++)
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
696 fprintf(stderr, "%d ", sp->avail_pmts[k]);
98
3fd15032fd3a tweak user interface for sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 96
diff changeset
697 fprintf(stderr, "\n");
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
698 #endif
98
3fd15032fd3a tweak user interface for sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 96
diff changeset
699
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
700 // PAT 再構築
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
701 result = RecreatePat(sp, buf, pos);
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
702 #if 0
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
703 int tc;
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
704 for(tc=0; tc<188; tc++)
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
705 fprintf(stderr, "%02x ", *(pat+tc));
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
706 #endif
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
707 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
708
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
709 return(result);
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
710 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
711
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
712 /**
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
713 * PAT 再構築処理
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
714 *
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
715 * PMT から出力対象チャンネル以外のチャンネル情報を削除し、PAT を再構築する
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
716 */
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
717 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
718 #if 0
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
719 unsigned char* buf, // [in] 読み込んだバッファ
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
720 unsigned char** pat, // [out] PAT 情報(再構築後)
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
721 unsigned char* pids, // [out] 出力対象 PID 情報
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
722 int *pos) // [in] 取得対象 PMT のバッファ中の位置
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
723 #endif
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
724 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
725 unsigned char y[LENGTH_CRC_DATA];
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
726 int crc;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
727 int i;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
728 int j;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
729 int pos_i;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
730 int pid_num = 0;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
731
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
732 // CRC 計算のためのデータ
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
733 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
734 // チャンネルによって変わらない部分
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
735 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
736 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
737 y[i] = buf[i + 5];
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
738 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
739 // チャンネルによって変わる部分
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
740 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
741 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
742 if(pos[i] != 0)
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
743 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
744 /* buf[pos_i] を y にコピー(抽出したPIDの数) */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
745 pos_i = pos[i];
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
746 for (j = 0; j < 4; j++)
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
747 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
748 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
749 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
750 pid_num++;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
751 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
752 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
753 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
754 /* パケットサイズ計算 */
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
755 y[2] = pid_num * 4 + 0x0d;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
756 // CRC 計算
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
757 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
758
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
759 // PAT 再構成
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
760 sp->pat = (unsigned char*)malloc(LENGTH_PACKET);
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
761 if(sp->pat == NULL)
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
762 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
763 fprintf(stderr, "RecreatePat() malloc error.\n");
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
764 return(TSS_NULL);
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
765 }
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
766 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
767 for (i = 0; i < 5; i++)
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
768 {
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
769 (sp->pat)[i] = buf[i];
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
770 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
771 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
772 {
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
773 (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
774 }
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
775 (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
776 (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
777 (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
778 (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
779
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
780 return(TSS_SUCCESS);
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
781 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
782
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
783 /**
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
784 * PMT 解析処理
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
785 *
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
786 * PMT を解析し、保存対象の PID を特定する
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
787 * TSヘッダとアダプテーションフィールドの処理は DemuxTs に一任するので、
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
788 * この内部では、セクションデータの先頭ポインタをもらってくる
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
789 */
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
790 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
791 #if 0
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
792 unsigned char* buf, // [in] セクション先頭
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
793 unsigned char* pids) // [out] 出力対象 PID 情報
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
794 #endif
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
795 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
796 unsigned char Nall;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
797 unsigned char N;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
798 int pcr;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
799 int epid;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
800 int av_flag = 0;
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
801
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
802 // Nall = ((buf[2] & 0x0F) << 4) + buf[3];
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
803 Nall = ((buf[2] & 0x0F) << 8) + buf[3];
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
804
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
805 /* get version */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
806 sp->program[sid].pmt_version = get_pmt_version(buf);
96
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 // PCR
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
809 pcr = GetPid(&buf[9]);
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
810 sp->pids[pcr] = 1;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
811 sp->program[sid].pcr_packet_id = pcr;
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
812
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
813 // 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
814 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
815 // 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
816
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
817 /*
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
818 * 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
819 * Value Desctiption
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
820 * 0x00 ITU-T | ISO/IEC Reserved
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
821 * 0x01 ISO/IEC 11172 Video
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
822 * 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
823 * 0x03 ISO/IEC 11172 Audio
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
824 * 0x04 ISO/IEC 13818-3 Audio
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
825 * 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
826 * 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
827 * 0x07 ISO/IEC 13522 MHEG
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
828 * 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
829 * 0x09 ITU-T Rec. H.222.1
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
830 * 0x0A ISO/IEC 13818-6 type A
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
831 * 0x0B ISO/IEC 13818-6 type B
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
832 * 0x0C ISO/IEC 13818-6 type C
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
833 * 0x0D ISO/IEC 13818-6 type D
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
834 * 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
835 * 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
836 * 0x10 ISO/IEC 14496-2 Visual
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
837 * 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
838 * 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
839 * 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
840 * 0x14 ISO/IEC 13818-6 Synchronized Download Protocol
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
841 * 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
842 * 0x80-0xFF User Private
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
843 *
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
844 */
104
afd25d9ebef6 output ECM packet so that former workaround is no longer needed.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 101
diff changeset
845
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
846 // ES PID
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
847 while (N < Nall + 8 - 4)
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
848 {
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
849 av_flag = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
850 if ( N > size ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
851 break;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
852 }
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
853 // ストリーム種別が 0x0D(type D)は出力対象外
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
854 if (0x0D != buf[N])
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
855 {
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
856 epid = GetPid(&buf[N + 1]);
100
aeba1988234f support macros to specify sid:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 99
diff changeset
857 sp->pids[epid] = 1;
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
858 if ( buf[N] == 0x02 ) { /* 13818-2 Video */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
859 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
860 sp->program[sid].video_nb += 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
861 av_flag = 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
862 } else if ( (buf[N] == 0x04) || (buf[N] == 0x0f) ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
863 /* 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
864 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
865 sp->program[sid].audio_nb += 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
866 av_flag = 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
867 } else {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
868 ; /* A/V どちらでもないものはとりあえずスルー */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
869 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
870 if ( av_flag ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
871 /* ESバッファはNULLか? */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
872 if ( sp->esbuf[epid] == NULL ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
873 sp->esbuf[epid] = malloc(sizeof(splitesbuf_t));
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
874 if ( sp->esbuf[epid] == NULL ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
875 fprintf(stderr, "malloc error\n");
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
876 return TSS_NULL;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
877 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
878 sp->esbuf[epid]->size = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
879 sp->esbuf[epid]->Program = &(sp->program[sid]);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
880 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
881 /* PESバッファはNULLか? */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
882 if ( sp->pesbuf[epid] == NULL ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
883 sp->pesbuf[epid] = malloc(sizeof(splitpesbuf_t));
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
884 if ( sp->pesbuf[epid] == NULL ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
885 fprintf(stderr, "malloc error\n");
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
886 return TSS_NULL;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
887 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
888 sp->pesbuf[epid]->size = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
889 sp->pesbuf[epid]->Program = &(sp->program[sid]);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
890 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
891 }
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
892 }
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
893 // 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
894 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
895 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
896 return TSS_SUCCESS;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
897 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
898
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
899 /**
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
900 * CRC 計算
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
901 */
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
902 static int GetCrc32(
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
903 unsigned char* data, // [in] CRC 計算対象データ
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
904 int len) // [in] CRC 計算対象データ長
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
905 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
906 int crc;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
907 int i, j;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
908 int c;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
909 int bit;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
910
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
911 crc = 0xFFFFFFFF;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
912 for (i = 0; i < len; i++)
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
913 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
914 char x;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
915 x = data[i];
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
916
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
917 for (j = 0; j < 8; j++)
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
918 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
919
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
920 bit = (x >> (7 - j)) & 0x1;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
921
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
922 c = 0;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
923 if (crc & 0x80000000)
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
924 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
925 c = 1;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
926 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
927
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
928 crc = crc << 1;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
929
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
930 if (c ^ bit)
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
931 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
932 crc ^= 0x04C11DB7;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
933 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
934
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
935 crc &= 0xFFFFFFFF;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
936 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
937 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
938
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
939 return crc;
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
940 }
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
941
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
942 /**
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
943 * PID 取得
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
944 */
99
3a3f15b063e1 now recpt1 accepts single sid for terrestrial channels.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 98
diff changeset
945 static int GetPid(
96
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
946 unsigned char* data) // [in] 取得対象データのポインタ
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
947 {
52f8e081763d add an option to specify the necessary service IDs.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
948 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
949 }
119
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
950
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
951 /* 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
952 (-1) if not available */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
953 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
954 const uint8_t *packet)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
955 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
956 int afc, len, flags;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
957 const uint8_t *p;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
958 unsigned int v;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
959
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
960 afc = (packet[3] >> 4) & 3;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
961 if (afc <= 1)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
962 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
963 p = packet + 4;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
964 len = p[0];
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
965 p++;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
966 if (len == 0)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
967 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
968 flags = *p++;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
969 len--;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
970 if (!(flags & 0x10))
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
971 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
972 if (len < 6)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
973 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
974 v = AV_RB32(p);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
975 *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
976 *ppcr_low = ((p[4] & 1) << 8) | p[5];
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
977 return 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
978 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
979
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
980 #if 0
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
981 /**
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
982 * TSを解析してPESを出力する
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
983 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
984 static int ts2pes(int64_t *ppts, int64_t *pdts, const uint8_t *packet, splitpesbuf_t *pesbuf, splitesbuf_t *esbuf, const int pid)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
985 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
986 /* 全体的に length がpacket長越えた時の処理を追記すること */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
987 /*
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
988 * PES先頭までの長さは
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
989 * 4byte : continity counter
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
990 * 27,28bit が adaptation fileld制御
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
991 * (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
992 * ペイロード長 = 188 - TS header(4byte) -adaptation field長 -1
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
993 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
994 int len_afh = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
995 *ppts = -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
996 *pdts = -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
997 int flags = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
998 const uint8_t *p;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
999 p = (uint8_t*)packet;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1000
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1001 flags = (p[3] & 0x30) >> 4;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1002 if ( flags == 0x02 || flags == 0x00) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1003 /* ペイロードなし */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1004 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1005 } else if ( flags == 0x03 ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1006 /* アダプテーションフィールド+ペイロード */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1007 /* アダプテーションフィールド長 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1008 len_afh = *(p+LENGTH_TS_HEADER) & 0xff;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1009 if ( len_afh > LENGTH_PACKET -LENGTH_TS_HEADER ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1010 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1011 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1012 if (!(p[1] & 0x40)) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1013 /* payload start unit indicator 発見 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1014 if ( pesbuf->size != 0 ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1015 pes2es(ppts, pdts, pesbuf, esbuf, pid);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1016 pesbuf->size = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1017 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1018 memcpy(pesbuf->buffer + pesbuf->size,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1019 packet +LENGTH_TS_HEADER +len_afh +1,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1020 LENGTH_PACKET -LENGTH_TS_HEADER -len_afh -1);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1021 pesbuf->size += LENGTH_PACKET -LENGTH_TS_HEADER -len_afh -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1022 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1023 /* PES先頭パケットではないのでバッファに書き込み */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1024 if ( pesbuf->size != 0 ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1025 memcpy(pesbuf->buffer + pesbuf->size,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1026 packet +LENGTH_TS_HEADER +len_afh +1,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1027 LENGTH_PACKET -LENGTH_TS_HEADER -len_afh -1);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1028 pesbuf->size += LENGTH_PACKET -LENGTH_TS_HEADER -len_afh -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1029 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1030 } else {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1031 /* ペイロードのみ */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1032 /* TSヘッダを取り除いてPESバッファ書き込み */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1033 if ( pesbuf->size != 0 ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1034 memcpy(pesbuf->buffer +pesbuf->size,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1035 packet +LENGTH_TS_HEADER,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1036 LENGTH_PACKET -LENGTH_TS_HEADER);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1037 pesbuf->size += LENGTH_PACKET -LENGTH_TS_HEADER;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1038 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1039 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1040 return 0;
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 #endif
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1043
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1044 /* pesbufが空か判定 (ret. 0:not empty / 1: empty) */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1045 static int pesbuf_empty(splitpesbuf_t *pesbuf){
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1046 return pesbuf->size == 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1047 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1048
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1049 /* pesbufをクリア */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1050 void pesbuf_clear(splitpesbuf_t *pesbuf){
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1051 pesbuf->size = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1052 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1053
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1054 /* pesbufにデータを追加 (ret. 0:success / -1:error) */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1055 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
1056 if(pesbuf->size + len > sizeof pesbuf->buffer){
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1057 //assert(0);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1058 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1059 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1060 memcpy(pesbuf->buffer +pesbuf->size, data, len);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1061 pesbuf->size += len;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1062 return 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1063 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1064
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1065 /* pesbufから、PESの先頭(packet_start_code_prefix)を探す */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1066 /* (ret. >=0:offset / -1: error) */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1067 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
1068 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
1069 int i = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1070
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1071 /* 小さすぎる */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1072 if(pesbuf->size < sizeof packet_start_code_prefix){
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1073 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1074 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1075 /* 先頭で探す */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1076 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
1077 return 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1078 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1079
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1080 #if 0
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1081 /* 先頭以外からも探す場合は、ここのコードを有効化する。 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1082 /* ただし、MPEG-Videoのstart_codeと同じなので、深追いしない方がいいと思う... */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1083 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
1084 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
1085 return i;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1086 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1087 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1088 #endif
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1089
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1090 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1091 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1092
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1093 /**
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1094 * TSの解析とDemuxを行う
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1095 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1096 //static int ts2pes(int64_t *ppts, int64_t *pdts, const uint8_t *packet, splitpesbuf_t *pesbuf, splitesbuf_t *esbuf, const int pid)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1097 static int DemuxTs(const uint8_t *packet, splitter *sp, const int pid, int *random_access)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1098 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1099 /*
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1100 * PES先頭までの長さは
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1101 * 4byte : continity counter
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1102 * 27,28bit が adaptation fileld制御
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1103 * (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
1104 * ペイロード長 = 188 - TS header(4byte) -adaptation field長 -1
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1105 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1106 /* ありがとう */
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 int payload_offset; /* ペイロードオフセット(=パケット先頭からのバイト数) */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1109 int payload_length; /* ペイロード長 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1110 int pes_started;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1111 int adaptation_field_control;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1112 int payload_unit_start_indicator;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1113 int random_access_indicator = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1114 int sid = sp->pid_sid_table[pid];
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1115
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1116 payload_offset = LENGTH_TS_HEADER;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1117
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1118 if ( sp->pesbuf[pid] == NULL ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1119 pes_started = 0; /* malloc走る前(セクション解析だったら呼んで良い) */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1120 } else {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1121 pes_started = !pesbuf_empty(sp->pesbuf[pid]); /* PES蓄積開始済み */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1122 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1123
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1124 /* adaptation_field_controlおよびadaptation_fieldを処理する */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1125 adaptation_field_control = (packet[3] & 0x30) >> 4;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1126 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
1127 /* ペイロードなしの場合 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1128 return 0; /* 別にエラーではない */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1129 } else if ( adaptation_field_control == 0x03 ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1130 /* アダプテーションフィールド+ペイロードの場合 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1131 if ( packet[LENGTH_TS_HEADER] != 0 ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1132 random_access_indicator = (packet[5] & 0x40) >> 6;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1133 sp->pesbuf[pid]->random_access_indicator = 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1134 sp->esbuf[pid]->random_access_indicator = 1;
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 /* ペイロード開始位置 = TSヘッダ長 + アダプテーションフィールド長 + 1 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1137 payload_offset += packet[LENGTH_TS_HEADER] + 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1138 } else {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1139 /* ペイロードのみ */
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
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1143 /* ペイロード長を出す */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1144 payload_length = LENGTH_PACKET - payload_offset;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1145 if( payload_length <= 0 ){ /* payload長が0以下の場合 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1146 return -1; /* エラーにすべきかは微妙なところ */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1147 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1148
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1149 /* payload_unit_start_indicatorを処理(1) */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1150 payload_unit_start_indicator = (packet[1] & 0x40) >> 6;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1151 /* (sectionの場合は、ここでpointer_fieldの処理などを行い、payload_offsetに反映する) */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1152 // if ( sp->pmt_pids[pid] == 2 ) { /* PID が録画対象の PMT であるか? */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1153 // int sid = search_pmt_program(sp, pid); /* PID が録画対象の PMT であるか? */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1154 if ( sp->pmt_pids[pid] == 2 ) { /* PID が録画対象の PMT であるか? */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1155 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
1156 /* pmt versionに差分あり */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1157 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
1158 " old_version[0x%02x]"
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1159 " new_version[0x%02x].\n",
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1160 pid,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1161 sp->program[sid].pmt_version,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1162 get_pmt_version(packet+payload_offset));
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1163 AnalyzePmt(sp, packet +payload_offset, sid, payload_length);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1164 /* payload 何byte処理したか等管理するべき */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1165 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1166 return 0; /* PMT の場合は処理終わり */
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
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1169 /* payload_unit_start_indicatorを処理(2) */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1170 /* 必要に応じ、蓄積済みPESの処理と、PES蓄積開始を行う */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1171 if( payload_unit_start_indicator ){
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1172 /* PES開始 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1173 if ( pes_started ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1174 /* バッファにデータがあればPES終端なので処理してクリア */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1175 pes2es(sp->pesbuf[pid], sp->esbuf[pid], pid);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1176 pesbuf_clear(sp->pesbuf[pid]);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1177 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1178 else {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1179 /* random_access_indicator からPES の蓄積を開始すると
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1180 * CS:動画がGOP先頭から蓄積されるが、
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1181 * 音声には random_access_indicator が表れないのでダメ
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1182 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1183 pes_started = 1;
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
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1187 /* PES蓄積処理 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1188 if ( pes_started ){
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1189 /* PES蓄積開始済み(これからPES蓄積開始を含む)なら、payloadをPESとして追加 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1190 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
1191 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1192 /* おつかれさまでした */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1193 return 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1194 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1195
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1196 /* PMT_PID から Program(Service ID)を確定させる */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1197 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
1198 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1199 int i;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1200 for ( i = 0; i < MAX_SERVICE_ID; i++ ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1201 if ( sp->program[i].pmt_packet_id == pid ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1202 return i;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1203 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1204 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1205 return -1;
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
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1208 /* esbufが空か判定 (ret. 0:not empty / 1: empty) */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1209 static int esbuf_empty(splitesbuf_t *esbuf){
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1210 return esbuf->size == 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1211 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1212
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1213 /* esbufをクリア */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1214 void esbuf_clear(splitesbuf_t *esbuf){
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1215 esbuf->random_access_indicator = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1216 esbuf->size = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1217 }
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 /* esbufにデータを追加 (ret. 0:success / -1:error) */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1220 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
1221 if(esbuf->size + len > sizeof esbuf->buffer){
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1222 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1223 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1224 memcpy(esbuf->buffer +esbuf->size, data, len);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1225 esbuf->size += len;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1226 return 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1227 }
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 * PESを解析してESを出力する
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 static int pes2es(splitpesbuf_t *pesbuf, splitesbuf_t *esbuf, const int pid)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1233 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1234 int len_pesh = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1235 int code = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1236 int flags = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1237 int len_pes = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1238 int len_pesh_supposed = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1239 int pes_extension_flags = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1240 int pes_extension_flags2 = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1241 int program_packet_sequence_counter_flag = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1242 int es_rate = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1243 const uint8_t *p = pesbuf->buffer;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1244 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
1245 int original_stuffing_length = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1246 int data_alignment_indicator = false;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1247 int es_started;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1248 int payload_offset = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1249 int payload_length = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1250 /* ありがとう */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1251 /* ありがとうとコメントを書くと、
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 * バグが減る
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1254 * バイナリサイズが小さくなる
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1255 * 画質がよくなる
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1256 * 音質がよくなる
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1257 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1258 if ( esbuf == NULL ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1259 return -1; /* malloc走る前この関数は呼んじゃダメです */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1260 } else {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1261 es_started = !esbuf_empty(esbuf); /* ES蓄積開始済み */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1262 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1263
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1264 payload_offset = pesbuf_packet_start_code_prefix(pesbuf);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1265 if ( payload_offset == -1 ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1266 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1267 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1268 p += payload_offset;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1269 #if 0
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1270 while( p < p_end -LENGTH_PES_HEADER -2) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1271 /* PES PREFIXが出現するまで読み捨てる */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1272 if ( (p[0] == 0x00 && p[1] == 0x00 && p[2] == 0x01) ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1273 break;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1274 } else {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1275 offset++;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1276 p++;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1277 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1278 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1279 if ( p >= p_end -LENGTH_PES_HEADER -2) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1280 return -1;
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 #endif
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1283 /* http://dvd.sourceforge.net/dvdinfo/pes-hdr.html
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1284 *
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1285 * Stream ID : type : extension present?
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1286 * (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
1287 * (1011 1110) 0xBE : Padding stream : NO
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1288 * (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
1289 * (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
1290 * (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
1291 * 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
1292 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1293 /* 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
1294 *
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1295 * 0xBC : プログラムストリームマップ
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1296 * 0xBD : プライベートストリーム1
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1297 * 0xBE : パディングストリーム
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1298 * 0xBF : プライベートストリーム2
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1299 * 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
1300 * 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
1301 * 0xF0 : ECMストリーム
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1302 * 0xF1 : EMMストリーム
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1303 * 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
1304 * 0xF3 : ISO/IEC 13522ストリーム
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1305 * 0xF4 : ITU-T勧告 H.222.1 type A
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1306 * 0xF5 : ITU-T勧告 H.222.1 type B
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1307 * 0xF6 : ITU-T勧告 H.222.1 type C
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1308 * 0xF7 : ITU-T勧告 H.222.1 type D
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1309 * 0xF8 : ITU-T勧告 H.222.1 type E
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1310 * 0xF9 : 補助ストリーム
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1311 * 0xFA : ISO/IEC 14496 1SLパケット化ストリーム
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1312 * 0xFB : ISO/IEC 14496 1フレックスマックスストリーム
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1313 * 0xFC : メタデータストリーム
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1314 * 0xFD : 拡張ストリームID
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1315 * 0xFE : 未定義
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1316 * 0xFF : プログラムストリームディレクトリ
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 * MPEG-1 or MPEG-2 audio stream と
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1320 * MPEG-1 or MPEG-2 video stream と
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1321 * Private stream 1 と
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1322 * 0xFD(拡張ストリームID)を抽出する
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1323 * ?0xBF Private stream 2 落としてるけどよいの?
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1324 * >多分よくない。ffmpegではここに入る前に PRIVATE_STREAM2 のコードが入っている
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1325 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1326 code = (p[3] &0xff) | 0x100;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1327 if ( !((code >= 0x1c0 && code <= 0x1df) ||
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1328 (code >= 0x1e0 && code <= 0x1ef) ||
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1329 (code == 0x1bd) || (code == 0x1fd))) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1330 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1331 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1332 /* PES のデータ長 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1333 /* 動画のストリームである場合には、ES長は不定となるので0が許容される */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1334 len_pes = AV_RB16(p+4);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1335 /* PESヘッダ拡張部(byte 6) */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1336 flags = p[6] & 0xff;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1337 if ( flags & 0x04 ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1338 data_alignment_indicator = true;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1339 /* data alignment indicator */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1340 /* video start code or audio syncword. */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1341 /* おそらくここで区切るとピクチャ単位 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1342 //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
1343 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1344 flags = p[7] & 0xff;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1345 /* PESヘッダデータ長(byte 8) */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1346 /*
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1347 * PESヘッダデータ長 = PESヘッダ拡張部の長さ + stuffing byteの長さ
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1348 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1349 /*
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1350 *len_pesh = flags(byte 7)のデータ合計(24)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1351 * +PES Extension flagのデータ合計(23)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1352 * +PES Extension flag2のデータ合計(127)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1353 * +stuffing byte(32) <- これもlen_peshの長さに混ぜていいの?
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1354 * MAX=206(?)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1355 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1356 len_pesh = p[8] & 0xff;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1357 p += LENGTH_PES_HEADER;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1358 payload_offset += LENGTH_PES_HEADER +len_pesh;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1359 if ( p +payload_offset >= p_end ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1360 /* PESヘッダ長すぎます */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1361 return -1;
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 /* flags
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 * name |byte 7(flags) |
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1367 * +-----+-----+-----+------+----------+----+----------+
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1368 * Bit |76 |5 |4 |3 |2 |1 |0 |
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1369 * +-----+-----+-----+------+----------+----+----------+
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1370 * field|PTS |ESCR |ES |DSM |additional|PES |PES |
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1371 * 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
1372 * |flag | |flag |mode |flag |flag|flag |
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1373 * +-----+-----+-----+------+----------+----+----------+
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1374 * 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
1375 * byte | | | | | | | |
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1376 * +-----+-----+-----+------+----------+----+----------+
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1377 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1378 if ( flags & PTS_FLAG ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1379 if ( p +LENGTH_PTS >= p_end ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1380 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1381 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1382 esbuf->pts = get_pts(p);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1383 p += LENGTH_PTS;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1384 len_pesh_supposed += LENGTH_PTS;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1385 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1386 if ( flags & DTS_FLAG ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1387 if ( p +LENGTH_PTS >= p_end ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1388 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1389 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1390 esbuf->dts = get_pts(p);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1391 p += LENGTH_PTS;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1392 len_pesh_supposed += LENGTH_PTS;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1393 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1394 if ( flags & ESCR_FLAG ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1395 p += 6;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1396 len_pesh_supposed += 6;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1397 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1398 if ( flags & ES_RATE_FLAG ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1399 es_rate = AV_RB24(p);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1400 es_rate = (es_rate >>1) & 0x3fffff;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1401 es_rate = es_rate * 50;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1402 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
1403 p += 3;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1404 len_pesh_supposed += 3;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1405 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1406 if ( flags & DSM_TRICK_MODE_FLAG ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1407 p += 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1408 len_pesh_supposed += 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1409 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1410 if ( flags & COPY_INFO_FLAG ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1411 p += 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1412 len_pesh_supposed += 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1413 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1414 if ( flags & CRC_FLAG ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1415 p += 2;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1416 len_pesh_supposed += 2;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1417 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1418 if ( flags & EXTENSION_FLAG ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1419 /* PES Extension flag
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1420 * +------------------------------------------------------------------+
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1421 * name |PES Extension flag |
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1422 * +-----------+-----------+----------------+------+---+--------------+
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1423 * bit |7 |6 |5 |4 |321|0 |
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1424 * +-----------+-----------+----------------+------+---+--------------+
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1425 * 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
1426 * name |data flag |field flag |packet |buffer| |flag2 |
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1427 * | | |sequence counter|flag | | |
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1428 * +-----------+-----------+----------------+------+---+--------------+
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1429 * Data |16 |1 |2 |2 | |1 |(23)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1430 * byte | | | | | | |
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1431 * +-----------+-----------+----------------+------+---+--------------+
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1432 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1433 if ( p >= p_end ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1434 return -1;
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 pes_extension_flags = *p & 0xff;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1437 p += 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1438 len_pesh_supposed += 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1439 if ( pes_extension_flags & PES_PRIVATE_DATA_FLAG ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1440 p += 16;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1441 len_pesh_supposed += 16;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1442 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1443 if ( pes_extension_flags & PACK_HEADER_FIELD_FLAG ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1444 p += 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1445 len_pesh_supposed += 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 if ( pes_extension_flags & PROGRAM_PACKET_SEQUENCE_COUNTER ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1448 if ( p >= p_end ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1449 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1450 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1451 program_packet_sequence_counter_flag = *p & 0xff;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1452 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
1453 p += 2;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1454 len_pesh_supposed += 2;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1455 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1456 if ( pes_extension_flags & PSTD_BUFFER_FLAG ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1457 p += 2;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1458 len_pesh_supposed += 2;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1459 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1460 if ( pes_extension_flags & PES_EXTENSION_FLAG2 ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1461 /* PES Extension flag2
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1462 * +------------------------------------------------------------------+
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1463 * name |PES Extension flag2 |
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1464 * +------+-----------------------------------------------------------+
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1465 * bit |7 |6543210 |
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1466 * +------+-----------------------------------------------------------+
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1467 * field|marker|PES_extension_field_length |
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1468 * name |bit | |
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1469 * |'1' | |
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1470 * +------+-----------------------------------------------------------+
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1471 * Data |- |0 <= N <= 127 |(127)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1472 * byte | | |
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1473 * +------+-----------------------------------------------------------+
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1474 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1475 if ( p >= p_end ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1476 return -1;
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 pes_extension_flags2 = *p & 0x7f;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1479 p += 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1480 len_pesh_supposed += 1;
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 p += pes_extension_flags2;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1483 len_pesh_supposed += pes_extension_flags2;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1484 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1485 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1486 #if 0
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1487 /*
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1488 * 画像であれば、PTS/DTSが立っていた場合に出力して、
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1489 * それ以外であれば、PTSが立っていた場合にのみ出力にすると、
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1490 * GOP的なまとまりで出力できる?
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1491 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1492 /* esbuf->size が 0 であるのはは初期化後、初めてここに到達した場合 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1493 if ((have_data_alignment_indicator) && (esbuf->size != 0)) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1494 /* ここのタイミングでパックヘッダつけてあげればPSになるはず */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1495 /* ピクチャ先頭パケット */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1496 write_es(esbuf, pid);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1497 memcpy(esbuf->buffer,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1498 pesbuf->buffer +offset +LENGTH_PES_HEADER +len_pesh,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1499 pesbuf->size -offset -LENGTH_PES_HEADER -len_pesh);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1500 esbuf->size = pesbuf->size -offset -LENGTH_PES_HEADER -len_pesh;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1501 } else if (have_data_alignment_indicator && (esbuf->size == 0)) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1502 /* プロセス起動してから最初のピクチャ先頭データ */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1503 memcpy(esbuf->buffer,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1504 pesbuf->buffer +offset +LENGTH_PES_HEADER +len_pesh,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1505 pesbuf->size -offset -LENGTH_PES_HEADER -len_pesh);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1506 esbuf->size = pesbuf->size -offset -LENGTH_PES_HEADER -len_pesh;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1507 } else if(esbuf->size != 0) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1508 /* それ以外のPESデータ */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1509 memcpy(esbuf->buffer + esbuf->size,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1510 pesbuf->buffer +offset +LENGTH_PES_HEADER +len_pesh,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1511 pesbuf->size -offset -LENGTH_PES_HEADER -len_pesh);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1512 esbuf->size += pesbuf->size -offset -LENGTH_PES_HEADER -len_pesh;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1513 } else {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1514 /* 読み捨て */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1515 /* プロセス起動直後のデータは捨てる(GOP境界をまたいだパケットから書き始めない為) */ }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1516 printf("len_pesh_supposed[%d], len_pesh[%d].\n", len_pesh_supposed, len_pesh);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1517 #endif
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1518 if ( data_alignment_indicator ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1519 if ( es_started ) { /* ES にデータが蓄積されている */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1520 if ( is_video_stream(pid, esbuf) ) { /* VIDEO である場合 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1521 /*
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1522 * ESにはピクチャ単位でデータが蓄積されている
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1523 * ESにGOPの開始コードが含まれているか調べて、
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1524 * 含まれていたら、蓄積開始のフラグを立てるのがいいかも…
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1525 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1526 if ( esbuf->random_access_indicator ) { /* TS の random_access ビットが立ったものがきているか? */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1527 /* 該当ストリームを蓄積する */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1528 esbuf->started = 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1529 esbuf->Program->video_start = 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1530 esbuf->Program->video_pts = esbuf->pts;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1531 } else {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1532 /* TS の random_access ビットが立ったものがきていない */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1533 /* 蓄積しない */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1534 esbuf_clear(esbuf);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1535 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1536 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1537 /* AAC の実験コードここから */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1538 /*
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1539 * オーディオを出力し始める条件(1. 2. を満たすこと)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1540 * 1. 動画の蓄積は開始されている
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1541 * 2. 動画のGOPの1番目のIピクチャのPTSとオーディオのPTSを比較して以下のどちらかを満たすこと
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1542 * 2.1. 差分が11msec以内
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1543 * 2.2. 過ぎている(過ぎている場合はオーディオESの蓄積の継続と次のGOP狙いにする?)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1544 * #GOP先頭にこだわり過ぎると録画を逃すという線もあるので、適当に手を打つのも手
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1545 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1546 else {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1547 esbuf->started = 1;
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 #if 0
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1550 if ( is_audio_stream(pid, esbuf) && esbuf->Program->video_start ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1551 int audio_lipsync_offset = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1552 int i;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1553 int64_t audio_pts = esbuf->pts;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1554 int adts_freq = AnalyzeAdifHeader(esbuf);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1555 int64_t adts_frame_time = ((1000/adts_freq) *27e6); /* PTSは27MHz */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1556 /* オーディオ且つ、Programのビデオ蓄積が開始されていればオーディオの蓄積を行う */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1557 while ( (esbuf->Program->video_pts > audio_pts +adts_frame_time/2) ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1558 /* オーディオデータを捨てると audio_pts は1フレーム分大きくなる */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1559 i = esbuf_adts_start_code_prefix(esbuf, audio_lipsync_offset); /* 次のAACのデータを取得 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1560 if ( i != -1 ) { /* AACデータの終端か? */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1561 audio_lipsync_offset += i;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1562 } else {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1563 break;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1564 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1565 audio_pts += adts_frame_time; /* AACの1フレーム分、時間を進める */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1566 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1567 if ( esbuf->size != audio_lipsync_offset ) { /* 一致していない場合はコピー */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1568 memmove(esbuf->buffer +audio_lipsync_offset,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1569 esbuf->buffer,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1570 esbuf->size -audio_lipsync_offset);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1571 esbuf->size -= audio_lipsync_offset;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1572 esbuf->started = 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1573 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1574 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1575 #endif
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1576 /* AAC の実験コードここまで */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1577 /* バッファをファイルに出力してクリア */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1578 if ( esbuf->started ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1579 esbuf_write(esbuf, pid);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1580 esbuf_clear(esbuf);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1581 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1582 } else {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1583 /* ES蓄積を新たに開始 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1584 es_started = 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1585 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1586 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1587
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1588 payload_length = pesbuf->size -payload_offset;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1589 /* ES蓄積処理 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1590 if ( es_started ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1591 /* ES蓄積開始済み(これからES蓄積開始を含む)なら、payloadをESとして追加 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1592 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
1593 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1594 /* お疲れさまでした */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1595 return 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1596 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1597
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1598 /* PIDはesbufのAUDIO STREAMの一つであるか? */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1599 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
1600 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1601 int i = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1602 int found = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1603 program_t* program = esbuf->Program;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1604 while (i < program->audio_nb)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1605 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1606 if (program->audio[i] == pid) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1607 found = 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1608 break;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1609 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1610 i++;
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 return found;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1613 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1614
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1615 /* PIDはesbufのVIDEO STREAMの一つであるか? */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1616 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
1617 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1618 int i = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1619 int found = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1620 program_t* program = esbuf->Program;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1621 while (i < program->video_nb)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1622 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1623 if (program->video[i] == pid) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1624 found = 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1625 break;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1626 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1627 i++;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1628 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1629 return found;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1630 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1631
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1632 /*
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1633 * ESをファイル出力する
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1634 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1635 int esbuf_write(splitesbuf_t *esbuf, int pid)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1636 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1637 int fd;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1638 int remain = esbuf->size;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1639 #define ES_FILE "/tmp/es.%d"
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1640 char filename[1024];
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1641 filename[0] = '\0';
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1642 umask(0133);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1643 snprintf(filename, sizeof(filename), ES_FILE, pid);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1644 fd = open(filename, O_CREAT|O_APPEND|O_RDWR, 00644);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1645 while(remain > 0)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1646 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1647 remain -= write(fd, esbuf->buffer+(esbuf->size-remain), remain);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1648 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1649 close(fd);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1650 return 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1651 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1652
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1653
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1654 /*
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1655 * packet dump
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1656 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1657 void dump_packet( const uint8_t *packet )
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1658 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1659 int i = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1660 uint8_t *p = (uint8_t*)packet;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1661 char tmp[17];
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1662
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1663 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
1664 while(i < LENGTH_PACKET) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1665 if ( (i%16) == 0 ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1666 printf("0x%04X ", i);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1667 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1668 printf("%02x ", *(p+i));
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1669 if ( isprint(*(p+i)) ){
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1670 tmp[i%16] = *(p+i);
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 tmp[i%16] = '.';
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1674 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1675 if ((i%16) == 15) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1676 tmp[sizeof(tmp)-1] = '\0';
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1677 printf(" %s\n", tmp);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1678 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1679 i++;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1680 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1681 putchar('\n');
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1682 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1683
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 * TOT の JST_time を解析する
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1686 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1687 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
1688 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1689 /* 注意事項
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1690 * 本当は TOT が有効かどうかをチェックするべきですがしていません
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 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1693 struct tm tm;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1694 time_t t2;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1695 int k;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1696 uint8_t *p = (uint8_t*)packet;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1697 unsigned int MJD;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1698 tm.tm_wday = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1699 tm.tm_yday = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1700 tm.tm_isdst = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1701
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1702 p += 8;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1703 MJD = (*(p) & 0xff) <<8;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1704 p++;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1705 MJD |= *(p) & 0xff;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1706 printf("MJD[%x].\n", MJD);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1707
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1708 /* ARIB STD-B10 第2部 付録C の公式より MJD to YYYYMMDD */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1709 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
1710 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
1711 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
1712 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
1713 k = 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1714 else
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1715 k = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1716 tm.tm_year += k;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1717 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
1718 tm.tm_mon--;
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 /* HHMISSは2進化10進数 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1721 p++;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1722 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
1723 p++;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1724 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
1725 p++;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1726 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
1727
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1728 *t = mktime(&tm);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1729 time(&t2);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1730 // printf("time[%d] TOT[%d].\n", t2, *t);
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 return TRUE;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1733 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1734
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1735 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
1736 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1737 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
1738 pts |= (AV_RB16(p + 1) >> 1) << 15;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1739 pts |= AV_RB16(p + 3) >> 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1740 return pts;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1741 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1742
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1743 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
1744 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1745 return ((p[6] >> 1) & 0x1f);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1746 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1747
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 #if 0
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1750 void forward_stc(timespec *stc, timespec offset)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1751 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1752 struct timespec local_timespec;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1753
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1754 clock_gettime(CLOCK_REALTIME, &local_timespec);
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 stc->tv_sec = local_timespec.tv_sec + offset.tv_sec;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1757 stc->tv_nsec = local_timespec.tv_nsec + offset.tv_nsec;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1758 if ( stc->tv_nsec >= 1 * 1000 * 1000 * 1000 ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1759 stc->tv_nsec -= 1 * 1000 * 1000 * 1000;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1760 stc->tv_sec += 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1761 } else if ( stc->tv_nsec < 0 ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1762 stc->tv_nsec = 1 * 1000 * 1000 * 1000 + stc->tv_nsec;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1763 stc->tv_sec -= 1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1764 }
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 #endif
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1767 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
1768 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1769 int i;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1770 uint8_t *p = (uint8_t*)packet;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1771 i = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1772 for( i=0; i < LENGTH_PACKET-4; i++) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1773 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
1774 dump_packet(packet );
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1775 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1776 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1777 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1778
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1779 /*
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1780 * この関数では、現在の仕様では、先頭位置の「次の」ADTS start codeまでの長さを返却します
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1781 * ret == 0 : 仕様上あり得ない
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1782 * ret > 0 : 見つかった場合
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1783 * ret == -1 : 見つからなかった場合
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1784 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1785 static int esbuf_adts_start_code_prefix(splitesbuf_t *esbuf, int offset)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1786 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1787 /*
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1788 * start code prefix のうち、先頭12bit は 1 固定であるが、13bit 目は id に該当
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1789 * MPEG4なオーディオが来た場合に対応出来ないので、13bit 目は見ないように改造するべき
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1790 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1791 uint8_t adts_start_code_prefix[2] = {0xFF, 0xF8}; /* とりあえず決め打ち */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1792 int i = offset +1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1793
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1794 /* 小さすぎる */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1795 if(esbuf->size -offset < sizeof adts_start_code_prefix){
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1796 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1797 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1798 for(i = 1; i < esbuf->size -offset - sizeof adts_start_code_prefix; i++) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1799 if(!memcmp(esbuf->buffer +offset + i ,adts_start_code_prefix, sizeof adts_start_code_prefix)){
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1800 #if 0
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1801 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
1802 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
1803 #endif
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1804 return i;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1805 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1806 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1807 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1808 }
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 /* ADIF HEADER解析 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1811 static int AnalyzeAdifHeader(splitesbuf_t *esbuf)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1812 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1813 int id = 0; /* 0:MPEG-4 1:MPEG-2 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1814 int layer = 0; /* 常に 0x00 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1815 int protection_absent = 0; /*保護属性 0:保護なし 1:保護あり */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1816 int profile = 0; /* 00:MAIN 01:LC 10:SSR 11:(reserved) */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1817 int sampling_frequency_index = 0; /* サンプリング周波数テーブル値 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1818 int private_bit = 0; /* private bit */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1819 int channel_configuration = 0; /* チャンネル数 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1820 int original_copy = 0;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1821 int home = 0; /* homeってなに? */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1822 int copyright_identification_bit = 0; /* 著作権証明ビット */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1823 int copyright_identification_start = 0; /* 著作権証明開始ビット */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1824 int aac_frame_length = 0; /* AACフレーム長 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1825 int adts_buffer_fullness = 0; /* ADTSバッファ残量 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1826 int no_raw_data_blocks_in_frame = 0; /* データブロックまでの残量 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1827 /*
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1828 * サンプリング周波数テーブル(ヘッダのINDEXが添字)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1829 * 単位:Hz
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1830 */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1831 int sampling_frequency_table[16] =
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1832 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1833 96000,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1834 88200,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1835 64000,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1836 48000,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1837 44100,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1838 32000,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1839 24000,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1840 22050,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1841 16000,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1842 12000,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1843 11025,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1844 8000,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1845 -1,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1846 -1,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1847 -1,
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1848 -1
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1849 };
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1850
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1851 uint8_t *p = esbuf->buffer;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1852 if ( esbuf->size < 8 ) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1853 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1854 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1855
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1856 id = get_adif_id(p+1);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1857 layer = get_adif_layer(p+1);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1858 protection_absent = get_adif_protection_absent(p+1);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1859 profile = get_adif_profile(p+2);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1860 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
1861 private_bit = get_adif_private_bit(p+2);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1862 channel_configuration = get_adif_channel_configuration(p+3);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1863 original_copy = get_adif_original_copy(p+3);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1864 home = get_adif_home(p+3);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1865 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
1866 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
1867 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
1868 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
1869 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
1870
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1871 /*
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1872 * とりあえず return は サンプリング周波数としておく
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 * 利用する予定もないので取得するだけにしておく
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 return sampling_frequency_table[sampling_frequency_index];
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1877 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1878
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1879 static int get_adif_id(uint8_t *p)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1880 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1881 return ((*p & 0x08) >>3);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1882 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1883
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1884 static int get_adif_layer(uint8_t *p)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1885 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1886 return ((*p & 0x06) >>1);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1887 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1888
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1889 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
1890 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1891 return (*p & 0x01);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1892 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1893
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1894 static int get_adif_profile(uint8_t *p)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1895 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1896 return ((*p & 0xc0) >>6);
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
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1899 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
1900 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1901 return ((*p & 0x3c) >>2);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1902 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1903
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1904 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
1905 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1906 return ((*p & 0x02) >>1);
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1907 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1908
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1909 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
1910 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1911 return ((*p & 0x01) <<2 | (*(p+1) & 0xc0 >>6) );
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1912 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1913
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1914 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
1915 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1916 return (*p & 0x20 >>5 );
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
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1919 static int get_adif_home(uint8_t *p)
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1920 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1921 return (*p & 0x10 >>4 );
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
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1924 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
1925 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1926 return (*p & 0x08 >>3 );
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1927 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1928
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1929 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
1930 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1931 return (*p & 0x04 >>2 );
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1932 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1933
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1934 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
1935 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1936 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
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 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
1940 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1941 return ( ((*p & 0x1f) <<6) || ((*(p+1) &0xfc) >>2));
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
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1944 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
1945 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1946 return (*p & 0x03);
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
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1949 /* GOP START CODE を検索する */
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1950 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
1951 {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1952 uint8_t gop_start_code[4] = {0x00, 0x00, 0x01, 0xb8};
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1953 int i;
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 if ( esbuf->size < sizeof gop_start_code ){
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1957 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1958 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1959 for(i = 0; i < esbuf->size - sizeof gop_start_code; i++) {
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1960 if(!memcmp(esbuf->buffer +i ,gop_start_code, sizeof gop_start_code)){
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1961 return i;
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 }
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1964 return -1;
4e7aaa72e158 ES out early release version.
Naoya OYAMA <naoya.oyama@gmail.com>
parents: 117
diff changeset
1965 }