1 /*
2  *  probe_stream.c
3  *
4  *  Copyright (C) Thomas Oestreich - June 2001
5  *
6  *  This file is part of transcode, a video stream processing tool
7  *
8  *  transcode is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2, or (at your option)
11  *  any later version.
12  *
13  *  transcode is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with GNU Make; see the file COPYING.  If not, write to
20  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  */
23 
24 #include "transcode.h"
25 #include "tcinfo.h"
26 #include "ioaux.h"
27 #include "probe_stream.h"
28 
29 #include "libtc/libtc.h"
30 #include "libtc/ratiocodes.h"
31 
32 
33 static ProbeInfo probe_info;
34 
guess_asr(ProbeInfo * info)35 static void guess_asr(ProbeInfo *info)
36 {
37     if (info != NULL && info->width != 0 && info->height != 0) {
38         double r = (double)info->width/(double)info->height;
39         tc_asr_code_from_value(&(info->asr), r);
40     }
41 }
42 
probe_file(info_t * ipipe)43 void probe_file(info_t *ipipe)
44 {
45     switch (ipipe->magic) {
46       case TC_MAGIC_AVI:
47         probe_avi(ipipe);
48         break;
49 
50       case TC_MAGIC_TIFF1:   /* image formats (multiple fallbacks) */
51       case TC_MAGIC_TIFF2:
52       case TC_MAGIC_JPEG:
53       case TC_MAGIC_BMP:
54       case TC_MAGIC_PNG:
55       case TC_MAGIC_GIF:
56       case TC_MAGIC_PPM:
57       case TC_MAGIC_PGM:
58       case TC_MAGIC_SGI:
59         probe_im(ipipe); /* ImageMagick serve all */
60         break;
61 
62       case TC_MAGIC_MXF:
63         probe_mxf(ipipe);
64         break;
65 
66       case TC_MAGIC_OGG:
67         probe_ogg(ipipe);
68         break;
69 
70       case TC_MAGIC_CDXA:
71         probe_pes(ipipe);
72         break;
73 
74       case TC_MAGIC_MPEG_PS: /* MPEG Program Stream */
75       case TC_MAGIC_VOB:     /* backward compatibility fallback */
76         probe_pes(ipipe);
77         break;
78 
79       case TC_MAGIC_MPEG_ES: /* MPEG Elementary Stream */
80       case TC_MAGIC_M2V:     /* backward compatibility fallback */
81         probe_pes(ipipe);
82         break;
83 
84       case TC_MAGIC_MPEG_PES:/* MPEG Packetized Elementary Stream */
85       case TC_MAGIC_MPEG:    /* backward compatibility fallback */
86         probe_pes(ipipe);
87         break;
88 
89       case TC_MAGIC_YUV4MPEG:
90         probe_yuv(ipipe);
91         break;
92 
93       case TC_MAGIC_NUV:
94         probe_nuv(ipipe);
95         break;
96 
97       case TC_MAGIC_MOV:
98         probe_mov(ipipe);
99         break;
100 
101       case TC_MAGIC_WAV:
102         probe_wav(ipipe);
103         break;
104 
105       case TC_MAGIC_DTS:
106         probe_dts(ipipe);
107         break;
108 
109       case TC_MAGIC_AC3:
110         probe_ac3(ipipe);
111         break;
112 
113       case TC_MAGIC_MP3:
114       case TC_MAGIC_MP3_2:
115       case TC_MAGIC_MP3_2_5:
116       case TC_MAGIC_MP2:
117         probe_mp3(ipipe);
118         break;
119 
120       case TC_MAGIC_DV_PAL:
121       case TC_MAGIC_DV_NTSC:
122         probe_dv(ipipe);
123         break;
124 
125       case TC_MAGIC_PV3:
126         probe_pv3(ipipe);
127         break;
128 
129       case TC_MAGIC_PVN:
130         probe_pvn(ipipe);
131         break;
132 
133       default:
134         /* libavcodec/libavformat it's a catchall too */
135         probe_ffmpeg(ipipe);
136     }
137     return;
138 }
139 
140 
probe_stream(info_t * ipipe)141 void probe_stream(info_t *ipipe)
142 {
143     verbose = ipipe->verbose;
144 
145     ipipe->probe_info = &probe_info;
146     ipipe->probe = 1;
147 
148     /* data structure will be filled by subroutines */
149     memset(&probe_info, 0, sizeof(ProbeInfo));
150     probe_info.magic = ipipe->magic;
151 
152     /* ------------------------------------------------------------
153      * check file type/magic and take action to probe for contents
154      * ------------------------------------------------------------*/
155 
156     /* not-plain-old-file stuff */
157     switch (ipipe->magic) {
158       case TC_MAGIC_MPLAYER:
159         probe_mplayer(ipipe);
160         break;
161 
162       case TC_MAGIC_VNC:
163         probe_vnc(ipipe);
164         break;
165 
166       case TC_MAGIC_V4L_VIDEO:
167       case TC_MAGIC_V4L_AUDIO:
168         probe_v4l(ipipe);
169         break;
170 
171       case TC_MAGIC_BKTR_VIDEO:
172         probe_bktr(ipipe);
173         break;
174 
175       case TC_MAGIC_SUNAU_AUDIO:
176         probe_sunau(ipipe);
177         break;
178 
179       case TC_MAGIC_BSDAV:
180         probe_bsdav(ipipe);
181         break;
182 
183       case TC_MAGIC_OSS_AUDIO:
184         probe_oss(ipipe);
185         break;
186 
187       case TC_MAGIC_DVD:
188       case TC_MAGIC_DVD_PAL:
189       case TC_MAGIC_DVD_NTSC:
190         probe_dvd(ipipe);
191         break;
192 
193       case TC_MAGIC_XML:
194         probe_xml(ipipe);
195         break;
196 
197       case TC_MAGIC_X11:
198         probe_x11(ipipe);
199         break;
200 
201       default: /* fallback to P.O.D. file... */
202         probe_file(ipipe);
203         break; /* for coherency */
204     }
205 
206     if (ipipe->magic == TC_MAGIC_XML) {
207         ipipe->probe_info->magic_xml = TC_MAGIC_XML;
208         /*
209          * used in transcode to load import_xml and to have
210          * the correct type of the video/audio
211          */
212     } else {
213         ipipe->probe_info->magic_xml = ipipe->probe_info->magic;
214     }
215     if (!ipipe->probe_info->asr) {
216         guess_asr(ipipe->probe_info);
217     }
218     return;
219 }
220 
221 /*************************************************************************/
222 
223 /*
224  * Local variables:
225  *   c-file-style: "stroustrup"
226  *   c-file-offsets: ((case-label . *) (statement-case-intro . *))
227  *   indent-tabs-mode: nil
228  * End:
229  *
230  * vim: expandtab shiftwidth=4:
231  */
232