~ubuntu-branches/ubuntu/intrepid/gstreamer0.10-ffmpeg/intrepid

« back to all changes in this revision

Viewing changes to gst-libs/ext/ffmpeg/libavformat/grab.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2006-12-13 23:10:28 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20061213231028-gb7p40u24i5dk331
Tags: 0.10.2-0ubuntu1
* Sync with pkg-gstreamer SVN:
  + debian/rules:
    - Enable the encoders again
* debian/control:
  + Add part about encoders to the description again

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
    int width, height;
63
63
    int video_fd, frame_size;
64
64
    int ret, frame_rate, frame_rate_base;
65
 
    int desired_palette;
 
65
    int desired_palette, desired_depth;
66
66
    struct video_tuner tuner;
67
67
    struct video_audio audio;
 
68
    struct video_picture pict;
68
69
    const char *video_device;
69
70
    int j;
70
71
 
71
 
    if (!ap || ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0)
 
72
    if (ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0) {
 
73
        av_log(s1, AV_LOG_ERROR, "Bad capture size (%dx%d) or wrong time base (%d)\n",
 
74
            ap->width, ap->height, ap->time_base.den);
 
75
 
72
76
        return -1;
 
77
    }
73
78
 
74
79
    width = ap->width;
75
80
    height = ap->height;
76
81
    frame_rate      = ap->time_base.den;
77
82
    frame_rate_base = ap->time_base.num;
78
83
 
79
 
    if((unsigned)width > 32767 || (unsigned)height > 32767)
 
84
    if((unsigned)width > 32767 || (unsigned)height > 32767) {
 
85
        av_log(s1, AV_LOG_ERROR, "Capture size is out of range: %dx%d\n",
 
86
            width, height);
 
87
 
80
88
        return -1;
 
89
    }
81
90
 
82
91
    st = av_new_stream(s1, 0);
83
92
    if (!st)
109
118
    }
110
119
 
111
120
    desired_palette = -1;
112
 
    if (st->codec->pix_fmt == PIX_FMT_YUV420P) {
 
121
    desired_depth = -1;
 
122
    if (ap->pix_fmt == PIX_FMT_YUV420P) {
113
123
        desired_palette = VIDEO_PALETTE_YUV420P;
114
 
    } else if (st->codec->pix_fmt == PIX_FMT_YUV422) {
 
124
        desired_depth = 12;
 
125
    } else if (ap->pix_fmt == PIX_FMT_YUV422) {
115
126
        desired_palette = VIDEO_PALETTE_YUV422;
116
 
    } else if (st->codec->pix_fmt == PIX_FMT_BGR24) {
 
127
        desired_depth = 16;
 
128
    } else if (ap->pix_fmt == PIX_FMT_BGR24) {
117
129
        desired_palette = VIDEO_PALETTE_RGB24;
 
130
        desired_depth = 24;
118
131
    }
119
132
 
120
133
    /* set tv standard */
135
148
    audio.flags &= ~VIDEO_AUDIO_MUTE;
136
149
    ioctl(video_fd, VIDIOCSAUDIO, &audio);
137
150
 
 
151
    ioctl(video_fd, VIDIOCGPICT, &pict);
 
152
#if 0
 
153
    printf("v4l: colour=%d hue=%d brightness=%d constrast=%d whiteness=%d\n",
 
154
           pict.colour,
 
155
           pict.hue,
 
156
           pict.brightness,
 
157
           pict.contrast,
 
158
           pict.whiteness);
 
159
#endif
 
160
    /* try to choose a suitable video format */
 
161
    pict.palette = desired_palette;
 
162
    pict.depth= desired_depth;
 
163
    if (desired_palette == -1 || (ret = ioctl(video_fd, VIDIOCSPICT, &pict)) < 0) {
 
164
        pict.palette=VIDEO_PALETTE_YUV420P;
 
165
        pict.depth=12;
 
166
        ret = ioctl(video_fd, VIDIOCSPICT, &pict);
 
167
        if (ret < 0) {
 
168
            pict.palette=VIDEO_PALETTE_YUV422;
 
169
            pict.depth=16;
 
170
            ret = ioctl(video_fd, VIDIOCSPICT, &pict);
 
171
            if (ret < 0) {
 
172
                pict.palette=VIDEO_PALETTE_RGB24;
 
173
                pict.depth=24;
 
174
                ret = ioctl(video_fd, VIDIOCSPICT, &pict);
 
175
                if (ret < 0)
 
176
                    pict.palette=VIDEO_PALETTE_GREY;
 
177
                    pict.depth=8;
 
178
                    ret = ioctl(video_fd, VIDIOCSPICT, &pict);
 
179
                    if (ret < 0)
 
180
                        goto fail1;
 
181
            }
 
182
        }
 
183
    }
 
184
 
138
185
    ret = ioctl(video_fd,VIDIOCGMBUF,&s->gb_buffers);
139
186
    if (ret < 0) {
140
187
        /* try to use read based access */
141
188
        struct video_window win;
142
 
        struct video_picture pict;
143
189
        int val;
144
190
 
145
191
        win.x = 0;
151
197
 
152
198
        ioctl(video_fd, VIDIOCSWIN, &win);
153
199
 
154
 
        ioctl(video_fd, VIDIOCGPICT, &pict);
155
 
#if 0
156
 
        printf("v4l: colour=%d hue=%d brightness=%d constrast=%d whiteness=%d\n",
157
 
               pict.colour,
158
 
               pict.hue,
159
 
               pict.brightness,
160
 
               pict.contrast,
161
 
               pict.whiteness);
162
 
#endif
163
 
        /* try to choose a suitable video format */
164
 
        pict.palette = desired_palette;
165
 
        if (desired_palette == -1 || (ret = ioctl(video_fd, VIDIOCSPICT, &pict)) < 0) {
166
 
            pict.palette=VIDEO_PALETTE_YUV420P;
167
 
            ret = ioctl(video_fd, VIDIOCSPICT, &pict);
168
 
            if (ret < 0) {
169
 
                pict.palette=VIDEO_PALETTE_YUV422;
170
 
                ret = ioctl(video_fd, VIDIOCSPICT, &pict);
171
 
                if (ret < 0) {
172
 
                    pict.palette=VIDEO_PALETTE_RGB24;
173
 
                    ret = ioctl(video_fd, VIDIOCSPICT, &pict);
174
 
                    if (ret < 0)
175
 
                        goto fail1;
176
 
                }
177
 
            }
178
 
        }
179
 
 
180
200
        s->frame_format = pict.palette;
181
201
 
182
202
        val = 1;
207
227
        s->gb_buf.frame = s->gb_frame % s->gb_buffers.frames;
208
228
        s->gb_buf.height = height;
209
229
        s->gb_buf.width = width;
210
 
        s->gb_buf.format = desired_palette;
211
 
 
212
 
        if (desired_palette == -1 || (ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf)) < 0) {
213
 
            s->gb_buf.format = VIDEO_PALETTE_YUV420P;
214
 
 
215
 
            ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf);
216
 
            if (ret < 0 && errno != EAGAIN) {
217
 
                /* try YUV422 */
218
 
                s->gb_buf.format = VIDEO_PALETTE_YUV422;
219
 
 
220
 
                ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf);
221
 
                if (ret < 0 && errno != EAGAIN) {
222
 
                    /* try RGB24 */
223
 
                    s->gb_buf.format = VIDEO_PALETTE_RGB24;
224
 
                    ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf);
225
 
                }
226
 
            }
227
 
        }
 
230
        s->gb_buf.format = pict.palette;
 
231
 
 
232
        ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf);
228
233
        if (ret < 0) {
229
234
            if (errno != EAGAIN) {
230
235
            fail1:
255
260
        frame_size = width * height * 3;
256
261
        st->codec->pix_fmt = PIX_FMT_BGR24; /* NOTE: v4l uses BGR24, not RGB24 ! */
257
262
        break;
 
263
    case VIDEO_PALETTE_GREY:
 
264
        frame_size = width * height * 1;
 
265
        st->codec->pix_fmt = PIX_FMT_GRAY8;
 
266
        break;
258
267
    default:
259
268
        goto fail;
260
269
    }
364
373
    return 0;
365
374
}
366
375
 
367
 
static AVInputFormat video_grab_device_format = {
 
376
AVInputFormat video_grab_device_demuxer = {
368
377
    "video4linux",
369
378
    "video grab",
370
379
    sizeof(VideoData),
847
856
    av_freep(&s->src_mem);
848
857
    return 0;
849
858
}
850
 
 
851
 
int video_grab_init(void)
852
 
{
853
 
    av_register_input_format(&video_grab_device_format);
854
 
    return 0;
855
 
}