2
mediastreamer2 library - modular sound and video processing and streaming
3
Copyright (C) 2006 Simon MORLAT (simon.morlat@linphone.org)
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public License
7
as published by the Free Software Foundation; either version 2
8
of the License, or (at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
#include "mediastreamer2/msfilter.h"
21
#include "mediastreamer2/msvideo.h"
23
#include <ffmpeg/avcodec.h>
25
typedef struct SizeConvState{
26
MSVideoSize target_vsize;
27
MSVideoSize input_vsize;
28
ImgReSampleContext *rsctx;
34
static int cif_yuv_size=0;
35
static int qcif_yuv_size=0;
36
static int qvga_yuv_size=0;
38
/*this MSFilter will do on the fly picture size conversion. It attempts to guess the picture size from the yuv buffer size. YUV420P is assumed on input.
39
For now it only supports QCIF->CIF, QVGA->CIF and CIF->CIF (does nothing in this case)*/
41
static void size_conv_init(MSFilter *f){
42
SizeConvState *s=ms_new(SizeConvState,1);
43
s->target_vsize.width = MS_VIDEO_SIZE_CIF_W;
44
s->target_vsize.height = MS_VIDEO_SIZE_CIF_H;
45
s->input_vsize.width = MS_VIDEO_SIZE_CIF_W;
46
s->input_vsize.height = MS_VIDEO_SIZE_CIF_H;
50
s->out_size=avpicture_get_size(PIX_FMT_YUV420P,s->target_vsize.width,s->target_vsize.height);
53
cif_yuv_size=avpicture_get_size(PIX_FMT_YUV420P,MS_VIDEO_SIZE_CIF_W,MS_VIDEO_SIZE_CIF_H);
54
qcif_yuv_size=avpicture_get_size(PIX_FMT_YUV420P,MS_VIDEO_SIZE_QCIF_W,MS_VIDEO_SIZE_QCIF_H);
55
qvga_yuv_size=avpicture_get_size(PIX_FMT_YUV420P,MS_VIDEO_SIZE_QVGA_W,MS_VIDEO_SIZE_QVGA_H);
59
static void size_conv_uninit(MSFilter *f){
60
SizeConvState *s=(SizeConvState*)f->data;
65
static void size_conv_postprocess(MSFilter *f){
66
SizeConvState *s=(SizeConvState*)f->data;
68
img_resample_close(s->rsctx);
73
static mblk_t * size_conv_alloc_mblk(SizeConvState *s){
75
int ref=s->om->b_datap->db_ref;
79
/*the last msg is still referenced by somebody else*/
80
ms_message("size_conv_alloc_mblk: Somebody still retaining yuv buffer (ref=%i)",ref);
85
s->om=allocb(s->out_size,0);
86
s->om->b_wptr=s->om->b_datap->db_lim;
90
static void init_resampler(SizeConvState *s, int size){
92
img_resample_close(s->rsctx);
96
if (size!=s->out_size){
97
if (size==cif_yuv_size){
98
s->input_vsize.width=MS_VIDEO_SIZE_CIF_W;
99
s->input_vsize.height=MS_VIDEO_SIZE_CIF_H;
100
}else if (size==qcif_yuv_size){
101
s->input_vsize.width=MS_VIDEO_SIZE_QCIF_W;
102
s->input_vsize.height=MS_VIDEO_SIZE_QCIF_H;
103
}else if (size==qvga_yuv_size){
104
s->input_vsize.width=MS_VIDEO_SIZE_QVGA_W;
105
s->input_vsize.height=MS_VIDEO_SIZE_QVGA_H;
107
ms_error("Unsupported image size !");
110
s->rsctx=img_resample_init(s->target_vsize.width,s->target_vsize.height,s->input_vsize.width,s->input_vsize.height);
114
static void size_conv_process(MSFilter *f){
115
SizeConvState *s=(SizeConvState*)f->data;
119
while((im=ms_queue_get(f->inputs[0]))!=NULL ){
122
init_resampler(s,sz);
125
avpicture_fill(&orig,(unsigned char *)im->b_rptr,PIX_FMT_YUV420P,s->input_vsize.width,s->input_vsize.height);
126
om=size_conv_alloc_mblk(s);
127
avpicture_fill(&dest,(uint8_t*)om->b_rptr,PIX_FMT_YUV420P,s->target_vsize.width,s->target_vsize.height);
128
img_resample(s->rsctx,&dest,&orig);
130
ms_queue_put(f->outputs[0],om);
132
ms_queue_put(f->outputs[0],im);
139
MSFilterDesc ms_size_conv_desc={
142
"a small video size converter",
150
size_conv_postprocess,
157
MSFilterDesc ms_size_conv_desc={
160
.text="a small video size converter",
163
.init=size_conv_init,
164
.process=size_conv_process,
165
.postprocess=size_conv_postprocess,
166
.uninit=size_conv_uninit
171
MS_FILTER_DESC_EXPORT(ms_size_conv_desc)