source: mediastreamer2/linphone/mediastreamer2/src/msvideo.c @ 41:528e9ebd8b36

Last change on this file since 41:528e9ebd8b36 was 41:528e9ebd8b36, checked in by smorlat <smorlat@…>, 5 years ago
  • on windows, start capture using driver's default pixel format.

It appears some drivers don't like trying multiple formats.

git-svn-id: svn+ssh://svn.savannah.nongnu.org/linphone/trunk@44 3f6dc0c8-ddfe-455d-9043-3cd528dc4637

File size: 3.9 KB
Line 
1/*
2mediastreamer2 library - modular sound and video processing and streaming
3Copyright (C) 2006  Simon MORLAT (simon.morlat@linphone.org)
4
5This program is free software; you can redistribute it and/or
6modify it under the terms of the GNU General Public License
7as published by the Free Software Foundation; either version 2
8of the License, or (at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18*/
19
20#include "mediastreamer2/msvideo.h"
21
22static void yuv_buf_init(YuvBuf *buf, int w, int h, uint8_t *ptr){
23        int ysize,usize;
24        ysize=w*h;
25        usize=ysize/4;
26        buf->w=w;
27        buf->h=h;
28        buf->planes[0]=ptr;
29        buf->planes[1]=buf->planes[0]+ysize;
30        buf->planes[2]=buf->planes[1]+usize;
31        buf->strides[0]=w;
32        buf->strides[1]=w/2;
33        buf->strides[2]=buf->strides[1];
34}
35
36int yuv_buf_init_from_mblk(YuvBuf *buf, mblk_t *m){
37        int size=m->b_wptr-m->b_rptr;
38        int w,h;
39        if (size==(MS_VIDEO_SIZE_QCIF_W*MS_VIDEO_SIZE_QCIF_H*3)/2){
40                w=MS_VIDEO_SIZE_QCIF_W;
41                h=MS_VIDEO_SIZE_QCIF_H;
42        }else if (size==(MS_VIDEO_SIZE_CIF_W*MS_VIDEO_SIZE_CIF_H*3)/2){
43                w=MS_VIDEO_SIZE_CIF_W;
44                h=MS_VIDEO_SIZE_CIF_H;
45        }else if (size==(MS_VIDEO_SIZE_QQVGA_W*MS_VIDEO_SIZE_QQVGA_H*3)/2){
46                w=MS_VIDEO_SIZE_QQVGA_W;
47                h=MS_VIDEO_SIZE_QQVGA_H;
48        }else if (size==(MS_VIDEO_SIZE_QVGA_W*MS_VIDEO_SIZE_QVGA_H*3)/2){
49                w=MS_VIDEO_SIZE_QVGA_W;
50                h=MS_VIDEO_SIZE_QVGA_H;
51        }else if (size==(MS_VIDEO_SIZE_VGA_W*MS_VIDEO_SIZE_VGA_H*3)/2){
52                w=MS_VIDEO_SIZE_VGA_W;
53                h=MS_VIDEO_SIZE_VGA_H;
54        }else if (size==(MS_VIDEO_SIZE_4CIF_W*MS_VIDEO_SIZE_4CIF_H*3)/2){
55                w=MS_VIDEO_SIZE_4CIF_W;
56                h=MS_VIDEO_SIZE_4CIF_H;
57        }else if (size==(MS_VIDEO_SIZE_720P_W*MS_VIDEO_SIZE_720P_H*3)/2){
58                w=MS_VIDEO_SIZE_720P_W;
59                h=MS_VIDEO_SIZE_720P_H;
60        }else if (size==(MS_VIDEO_SIZE_NS1_W*MS_VIDEO_SIZE_NS1_H*3)/2){
61                w=MS_VIDEO_SIZE_NS1_W;
62                h=MS_VIDEO_SIZE_NS1_H;
63        }else if (size==(MS_VIDEO_SIZE_1024_W*MS_VIDEO_SIZE_1024_H*3)/2){
64                w=MS_VIDEO_SIZE_1024_W;
65                h=MS_VIDEO_SIZE_1024_H;
66        }else if (size==(160*112*3)/2){/*format used by econf*/
67                w=160;
68                h=112;
69        }else {
70                ms_error("Unsupported image size: size=%i (bug somewhere !)",size);
71                return -1;
72        }
73        yuv_buf_init(buf,w,h,m->b_rptr);
74        return 0;
75}
76
77void yuv_buf_init_from_mblk_with_size(YuvBuf *buf, mblk_t *m, int w, int h){
78        yuv_buf_init(buf,w,h,m->b_rptr);
79}
80
81mblk_t * yuv_buf_alloc(YuvBuf *buf, int w, int h){
82        int size=(w*h*3)/2;
83        mblk_t *msg=allocb(size,0);
84        yuv_buf_init(buf,w,h,msg->b_wptr);
85        msg->b_wptr+=size;
86        return msg;
87}
88
89static void plane_copy(const uint8_t *src_plane, int src_stride,
90        uint8_t *dst_plane, int dst_stride, MSVideoSize roi){
91        int i;
92        for(i=0;i<roi.height;++i){
93                memcpy(dst_plane,src_plane,roi.width);
94                src_plane+=src_stride;
95                dst_plane+=dst_stride;
96        }
97}
98
99void yuv_buf_copy(uint8_t *src_planes[], const int src_strides[], 
100                uint8_t *dst_planes[], const int dst_strides[3], MSVideoSize roi){
101        plane_copy(src_planes[0],src_strides[0],dst_planes[0],dst_strides[0],roi);
102        roi.width=roi.width/2;
103        roi.height=roi.height/2;
104        plane_copy(src_planes[1],src_strides[1],dst_planes[1],dst_strides[1],roi);
105        plane_copy(src_planes[2],src_strides[2],dst_planes[2],dst_strides[2],roi);
106}
107
108#ifndef MAKEFOURCC
109#define MAKEFOURCC(a,b,c,d) ((d)<<24 | (c)<<16 | (b)<<8 | (a))
110#endif
111
112MSPixFmt ms_fourcc_to_pix_fmt(uint32_t fourcc){
113        MSPixFmt ret;
114        switch (fourcc){
115                case MAKEFOURCC('I','4','2','0'):
116                        ret=MS_YUV420P;
117                break;
118                case MAKEFOURCC('Y','U','Y','2'):
119                        ret=MS_YUY2;
120                break;
121                case MAKEFOURCC('Y','U','Y','V'):
122                        ret=MS_YUYV;
123                break;
124                case MAKEFOURCC('U','Y','V','Y'):
125                        ret=MS_UYVY;
126                break;
127                case 0: /*BI_RGB on windows*/
128                        ret=MS_RGB24;
129                break;
130                default:
131                        ret=MS_PIX_FMT_UNKNOWN;
132        }
133        return ret;
134}
135
Note: See TracBrowser for help on using the repository browser.