1 /***************************************************************************
2                           \fn ADM_VideoEncoders
3                           \brief Internal handling of video encoders
4                              -------------------
5 
6     copyright            : (C) 2002/2009 by mean
7     email                : fixounet@free.fr
8  ***************************************************************************/
9 
10 /***************************************************************************
11  *                                                                         *
12  *   This program is free software; you can redistribute it and/or modify  *
13  *   it under the terms of the GNU General Public License as published by  *
14  *   the Free Software Foundation; either version 2 of the License, or     *
15  *   (at your option) any later version.                                   *
16  *                                                                         *
17  ***************************************************************************/
18 #include "ADM_default.h"
19 #include "ADM_yv12Encoder.h"
20 
21 /**
22         \fn ADM_yv12Encoder
23 */
ADM_yv12Encoder(ADM_coreVideoFilter * src,bool globalHeader)24 ADM_yv12Encoder::ADM_yv12Encoder(ADM_coreVideoFilter *src,bool globalHeader) : ADM_coreVideoEncoder(src)
25 {
26     ADM_info("[YV12Encoder] Creating.\n");
27     int w,h;
28     FilterInfo *info=src->getInfo();
29     w=info->width;
30     h=info->height;
31     image=new ADMImageDefault(w,h);
32     plane=(w*h*3)/2;
33 }
34 /**
35     \fn ~ADM_yv12Encoder
36 */
~ADM_yv12Encoder()37 ADM_yv12Encoder::~ADM_yv12Encoder()
38 {
39     ADM_info("[YV12Encoder] Destroying.\n");
40 }
41 
42 
43 /**
44     \fn encode
45 */
encode(ADMBitstream * out)46 bool         ADM_yv12Encoder::encode (ADMBitstream * out)
47 {
48     uint32_t fn;
49     if(source->getNextFrame(&fn,image)==false)
50     {
51         ADM_info("[YV12] Cannot get next image\n");
52         return false;
53     }
54     ADM_assert(out->bufferSize>plane);
55     //--
56     int w=image->GetWidth(PLANAR_Y);
57     int h=image->GetHeight(PLANAR_Y);
58 
59     ADMImageRefWrittable packed(w,h);
60     uint32_t square=w*h;
61     packed._planes[0]=out->data;
62     packed._planes[1]=out->data+square;
63     packed._planes[2]=out->data+((square*5)>>2);
64 
65     packed._planeStride[0]=w;
66     packed._planeStride[1]=packed._planeStride[2]=w>>1;
67 
68     packed.duplicate(image);
69     out->len=plane;
70     out->pts=out->dts=image->Pts;
71     out->flags=AVI_KEY_FRAME;
72     return true;
73 }
74 
75 // EOF
76