1 /*
2  * This file is part of MPlayer.
3  *
4  * MPlayer is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * MPlayer is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <sys/types.h>
23 #include <unistd.h>
24 #include <math.h>
25 
26 #include "config.h"
27 
28 #include "img_format.h"
29 
30 #include <libdv/dv.h>
31 #include <libdv/dv_types.h>
32 
33 #include "stream/stream.h"
34 #include "libmpdemux/demuxer.h"
35 #include "libmpdemux/stheader.h"
36 
37 #include "vd_internal.h"
38 #include "vd_libdv.h"
39 
40 static const vd_info_t info =
41 {
42 	"Raw DV Video Decoder",
43 	"libdv",
44 	"Alexander Neundorf <neundorf@kde.org>",
45 	"http://libdv.sf.net",
46 	"native codec"
47 };
48 
LIBVD_EXTERN(libdv)49 LIBVD_EXTERN(libdv)
50 
51 // to set/get/query special features/parameters
52 static int control(sh_video_t *sh,int cmd,void* arg,...){
53     return CONTROL_UNKNOWN;
54 }
55 
56 static dv_decoder_t* global_rawdv_decoder=NULL;
57 
init_global_rawdv_decoder(void)58 dv_decoder_t* init_global_rawdv_decoder(void)
59 {
60  if(!global_rawdv_decoder){
61    global_rawdv_decoder=dv_decoder_new(TRUE,TRUE,FALSE);
62    global_rawdv_decoder->quality=DV_QUALITY_BEST;
63    global_rawdv_decoder->prev_frame_decoded = 0;
64  }
65  return global_rawdv_decoder;
66 }
67 
68 // init driver
init(sh_video_t * sh)69 static int init(sh_video_t *sh)
70 {
71    sh->context = (void *)init_global_rawdv_decoder();
72    return mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_YUY2);
73 }
74 
75 // uninit driver
uninit(sh_video_t * sh)76 static void uninit(sh_video_t *sh){
77 }
78 
79 // decode a frame
decode(sh_video_t * sh,void * data,int len,int flags)80 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags)
81 {
82    mp_image_t* mpi;
83    dv_decoder_t *decoder=sh->context;
84 
85    if(len<=0 || (flags&3)){
86 //      fprintf(stderr,"decode() (rawdv) SKIPPED\n");
87       return NULL; // skipped frame
88    }
89 
90    dv_parse_header(decoder, data);
91 
92    mpi=mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, sh->disp_w, sh->disp_h);
93 
94    if(!mpi){	// temporary!
95       fprintf(stderr,"couldn't allocate image for stderr codec\n");
96       return NULL;
97    }
98 
99    dv_decode_full_frame(decoder, data, e_dv_color_yuv, mpi->planes, mpi->stride);
100 
101    return mpi;
102 }
103