1 /*
2 * probe_bsdav.c
3 *
4 * Copyright (C) Jacob Meuser <jakemsr@jakemsr.com> - May 2005
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 "tc.h"
28 #include "libtc/libtc.h"
29 #include "libtc/ratiocodes.h"
30
31 #ifdef HAVE_BSDAV
32
33 #include <bsdav.h>
34
probe_bsdav(info_t * ipipe)35 void probe_bsdav(info_t *ipipe)
36 {
37 struct bsdav_stream_header strhdr;
38 FILE *file;
39
40 if ((file = fdopen(ipipe->fd_in, "r")) == NULL) {
41 tc_log_error(__FILE__, "failed to fdopen bsdav stream");
42 ipipe->error = 1;
43 return;
44 }
45
46 /* read stream header */
47 if (bsdav_read_stream_header(file, &strhdr) != 0) {
48 tc_log_error(__FILE__, "failed to read bsdav stream header");
49 ipipe->error = 1;
50 return;
51 }
52
53 ipipe->probe_info->width = strhdr.vidwth;
54 ipipe->probe_info->height = strhdr.vidhgt;
55 ipipe->probe_info->track[0].samplerate = strhdr.audsrt;
56 ipipe->probe_info->track[0].chan = strhdr.audchn;
57 ipipe->probe_info->track[0].bits = bsdav_aud_fmts[strhdr.audfmt].bps;
58 ipipe->probe_info->track[0].format = 0x1;
59
60 ipipe->probe_info->magic = TC_MAGIC_BSDAV;
61
62 switch (strhdr.vidfmt) {
63 case BSDAV_VIDFMT_I420:
64 ipipe->probe_info->codec = TC_CODEC_YUV420P;
65 break;
66 case BSDAV_VIDFMT_YUY2:
67 ipipe->probe_info->codec = TC_CODEC_YUY2;
68 break;
69 case BSDAV_VIDFMT_UYVY:
70 ipipe->probe_info->codec = TC_CODEC_UYVY;
71 break;
72 default:
73 ipipe->probe_info->codec = TC_CODEC_UNKNOWN;
74 break;
75 }
76
77 if (ipipe->probe_info->track[0].chan > 0)
78 ipipe->probe_info->num_tracks = 1;
79
80 if (fseek(file, 0, SEEK_SET) != 0) {
81 tc_log_error(__FILE__, "failed to fseek bsdav stream");
82 ipipe->error = 1;
83 return;
84 }
85
86 ipipe->probe_info->fps = bsdav_probe_frame_rate(file,
87 ipipe->factor * 1024 * 1024);
88
89 tc_frc_code_from_value(&(ipipe->probe_info->frc),
90 ipipe->probe_info->fps);
91
92 return;
93 }
94
95 #else /* HAVE_BSDAV */
96
97 void
probe_bsdav(info_t * ipipe)98 probe_bsdav(info_t * ipipe)
99 {
100 tc_log_error(__FILE__, "No support for bsdav compiled in");
101 ipipe->probe_info->codec = TC_CODEC_UNKNOWN;
102 ipipe->probe_info->magic = TC_MAGIC_UNKNOWN;
103 }
104
105
106 #endif
107