annotate src/mediastreamer/msavdecoder.c @ 12767:53218d758ba9

[gaim-migrate @ 15114] Make the dns lookup for udp connecting asynchronous. Thomas pointed out that it should be instantaneous anyway because the SRV lookup that has just been done, but this'll avoid blocking if the SRV lookup failed or something. committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Sun, 08 Jan 2006 22:09:28 +0000
parents e67993da8a22
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12024
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1 /*
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2 The mediastreamer library aims at providing modular media processing and I/O
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3 for linphone, but also for any telephony application.
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4 Copyright (C) 2001 Simon MORLAT simon.morlat@linphone.org
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
6 This library is free software; you can redistribute it and/or
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
7 modify it under the terms of the GNU Lesser General Public
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
8 License as published by the Free Software Foundation; either
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
9 version 2.1 of the License, or (at your option) any later version.
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
10
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
11 This library is distributed in the hope that it will be useful,
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
14 Lesser General Public License for more details.
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
15
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
16 You should have received a copy of the GNU Lesser General Public
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
17 License along with this library; if not, write to the Free Software
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
19 */
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
20
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
21 #include "msavdecoder.h"
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
22 #include "mscodec.h"
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
23 extern MSFilter *ms_mpeg_encoder_new();
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
24 extern MSFilter *ms_mpeg4_encoder_new();
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
25 extern MSFilter *ms_h263_encoder_new();
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
26
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
27
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
28 MSCodecInfo MPEGinfo={
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
29 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
30 "MPEG1 codec",
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
31 0,
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
32 MS_FILTER_VIDEO_CODEC,
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
33 ms_mpeg_encoder_new,
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
34 "This is a MPEG1 codec taken from the ffmpeg project."
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
35 },
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
36 ms_mpeg_encoder_new,
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
37 ms_mpeg_decoder_new,
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
38 0,
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
39 0,
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
40 0, /*bitrate */
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
41 0, /*sample freq */
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
42 0,
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
43 "MPV",
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
44 1,
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
45 1
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
46 };
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
47
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
48 MSCodecInfo h263info={
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
49 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
50 "H263 codec",
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
51 0,
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
52 MS_FILTER_VIDEO_CODEC,
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
53 ms_h263_encoder_new,
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
54 "This is a H263 codec taken from the ffmpeg project."
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
55 },
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
56 ms_h263_encoder_new,
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
57 ms_h263_decoder_new,
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
58 0,
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
59 0,
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
60 0, /*bitrate */
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
61 0, /*sample freq */
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
62 0,
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
63 "H263",
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
64 1,
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
65 1
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
66 };
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
67
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
68 MSCodecInfo MPEG4info={
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
69 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
70 "MPEG4 codec",
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
71 0,
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
72 MS_FILTER_VIDEO_CODEC,
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
73 ms_mpeg4_encoder_new,
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
74 "This is a MPEG4 codec taken from the ffmpeg project."
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
75 },
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
76 ms_mpeg4_encoder_new,
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
77 ms_mpeg4_decoder_new,
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
78 0,
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
79 0,
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
80 0, /*bitrate */
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
81 0, /*sample freq */
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
82 0,
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
83 "MP4V-ES",
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
84 1,
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
85 1
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
86 };
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
87
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
88
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
89 void ms_AVCodec_init()
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
90 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
91 avcodec_init();
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
92 avcodec_register_all();
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
93 ms_filter_register((MSFilterInfo*)&h263info);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
94 //ms_filter_register((MSFilterInfo*)&MPEG4info);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
95 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
96
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
97
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
98 static MSAVDecoderClass *ms_avdecoder_class=NULL;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
99
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
100 MSFilter *ms_h263decoder_new()
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
101 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
102 return ms_AVdecoder_new_with_codec(CODEC_ID_H263);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
103 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
104
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
105 MSFilter *ms_mpeg_decoder_new()
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
106 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
107 return ms_AVdecoder_new_with_codec(CODEC_ID_MPEG1VIDEO);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
108 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
109
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
110 MSFilter *ms_mpeg4_decoder_new()
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
111 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
112 return ms_AVdecoder_new_with_codec(CODEC_ID_MPEG4);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
113 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
114
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
115 MSFilter *ms_h263_decoder_new(){
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
116 return ms_AVdecoder_new_with_codec(CODEC_ID_H263);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
117 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
118
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
119 MSFilter * ms_AVdecoder_new_with_codec(enum CodecID codec_id)
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
120 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
121 MSAVDecoder *enc;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
122
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
123 enc=g_malloc0(sizeof(MSAVDecoder));
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
124 if (ms_avdecoder_class==NULL)
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
125 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
126 ms_avdecoder_class=g_malloc0(sizeof(MSAVDecoderClass));
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
127 ms_AVdecoder_class_init(ms_avdecoder_class);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
128 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
129 MS_FILTER(enc)->klass=(MSFilterClass*)ms_avdecoder_class;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
130 ms_AVdecoder_init(enc,avcodec_find_decoder(codec_id));
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
131 return MS_FILTER(enc);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
132 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
133
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
134
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
135 void ms_AVdecoder_init(MSAVDecoder *dec, AVCodec *codec)
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
136 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
137 gint error;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
138
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
139 ms_filter_init(MS_FILTER(dec));
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
140 MS_FILTER(dec)->inqueues=dec->q_inputs;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
141 MS_FILTER(dec)->outqueues=dec->q_outputs;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
142 avcodec_get_context_defaults(&dec->av_context);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
143 dec->av_codec=codec;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
144 dec->av_opened=0;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
145 dec->skip_gob=1;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
146 dec->obufwrap=NULL;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
147 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
148
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
149 void ms_AVdecoder_class_init(MSAVDecoderClass *klass)
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
150 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
151 ms_filter_class_init(MS_FILTER_CLASS(klass));
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
152 ms_filter_class_set_name( MS_FILTER_CLASS(klass),"AVdecoder");
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
153 MS_FILTER_CLASS(klass)->max_qinputs=MSAVDECODER_MAX_INPUTS;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
154 MS_FILTER_CLASS(klass)->max_qoutputs=MSAVDECODER_MAX_INPUTS;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
155 MS_FILTER_CLASS(klass)->r_maxgran=0;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
156 MS_FILTER_CLASS(klass)->w_maxgran=0;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
157 MS_FILTER_CLASS(klass)->destroy=(MSFilterDestroyFunc)ms_AVdecoder_destroy;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
158 MS_FILTER_CLASS(klass)->process=(MSFilterProcessFunc)ms_AVdecoder_process;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
159 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
160
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
161 void ms_AVdecoder_uninit(MSAVDecoder *dec)
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
162 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
163 if (dec->obufwrap!=NULL) ms_buffer_destroy(dec->obufwrap);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
164 if (dec->av_opened) avcodec_close(&dec->av_context);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
165 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
166 void ms_AVdecoder_destroy( MSAVDecoder *obj)
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
167 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
168 ms_AVdecoder_uninit(obj);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
169 g_free(obj);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
170 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
171
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
172 gint ms_AVdecoder_set_format(MSAVDecoder *dec, gchar *fmt)
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
173 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
174 gint format;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
175 if (strcmp(fmt,"YUV420P")==0) format=PIX_FMT_YUV420P;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
176 else if (strcmp(fmt,"YUV422")==0) format=PIX_FMT_YUV422;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
177 else if (strcmp(fmt,"RGB24")==0) format=PIX_FMT_RGB24;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
178 else if (strcmp(fmt,"BGR24")==0) format=PIX_FMT_BGR24;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
179 else if (strcmp(fmt,"YUV422P")==0) format=PIX_FMT_YUV422P;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
180 else if (strcmp(fmt,"YUV444P")==0) format=PIX_FMT_YUV444P;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
181 else {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
182 g_warning("ms_AVdecoder_set_format: unsupported format %s.",fmt);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
183 return -1;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
184 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
185 dec->output_pix_fmt=format;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
186 return 0;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
187 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
188
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
189 void ms_AVdecoder_process(MSAVDecoder *r)
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
190 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
191 AVFrame orig;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
192 AVFrame transformed;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
193 MSQueue *inq,*outq;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
194 MSMessage *inm,*outm;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
195 gint error;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
196 gint got_picture;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
197 gint len;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
198 unsigned char *data;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
199 AVCodecContext *ctx=&r->av_context;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
200 gint gob_num;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
201
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
202 inq=r->q_inputs[0];
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
203 outq=r->q_outputs[0];
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
204
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
205 /* get a picture from the input queue */
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
206 inm=ms_queue_get(inq);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
207 g_return_if_fail(inm!=NULL);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
208 if (inm->size > 0)
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
209 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
210 guint32 *p = inm->data;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
211
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
212 if (!r->av_opened){
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
213 error=avcodec_open(&r->av_context, r->av_codec);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
214 if (error!=0) g_warning("avcodec_open() failed: %i",error);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
215 else r->av_opened=1;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
216 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
217
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
218 gob_num = (ntohl(*p) >> 10) & 0x1f;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
219 ms_trace("gob %i, size %i", gob_num, inm->size);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
220 ms_trace("ms_AVdecoder_process: received %08x %08x", ntohl(p[0]), ntohl(p[1]));
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
221
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
222 /* remove H.263 Payload Header */
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
223 p[0] = htonl( ntohl(p[0]) & 0x0000ffff );
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
224
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
225 if (gob_num == 0){
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
226 if (r->skip_gob == 0)
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
227 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
228 unsigned char *data = r->buf_compressed;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
229 ms_trace("ms_AVdecoder_process: decoding %08x %08x %08x", ntohl(((unsigned int *)data)[0]), ntohl(((unsigned int *)data)[1]), ntohl(((unsigned int *)data)[2]));
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
230 while (r->buf_size > 0) {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
231 len=avcodec_decode_video(&r->av_context,&orig,&got_picture,data,r->buf_size /*inm->size*/);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
232 if (len<0) {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
233 ms_warning("ms_AVdecoder_process: error %i.",len);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
234 break;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
235 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
236 if (got_picture) {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
237 ms_trace("ms_AVdecoder_process: got_picture: width=%i height=%i fmt=%i",
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
238 ctx->width,ctx->height,ctx->pix_fmt);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
239 /* set the image in the wanted format */
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
240 outm=ms_message_alloc();
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
241 if (r->obufwrap==NULL){
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
242 r->obufwrap=ms_buffer_new(avpicture_get_size(r->output_pix_fmt,ctx->width,ctx->height));
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
243 r->obufwrap->ref_count++;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
244 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
245 ms_message_set_buf(outm,r->obufwrap);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
246 avpicture_fill(&transformed,outm->data,r->output_pix_fmt,ctx->width,ctx->height);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
247 img_convert(&transformed, r->output_pix_fmt,
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
248 &orig,ctx->pix_fmt,ctx->width,ctx->height);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
249 ms_queue_put(outq,outm);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
250 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
251 r->buf_size -= len;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
252 data += len;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
253 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
254 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
255 else {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
256 r->skip_gob = 0;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
257 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
258 memcpy(r->buf_compressed, inm->data, inm->size);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
259 r->buf_size = inm->size;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
260 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
261 else {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
262 memcpy(r->buf_compressed + r->buf_size, inm->data, inm->size);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
263 r->buf_size += inm->size;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
264 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
265 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
266 ms_message_destroy(inm);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
267 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
268
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
269
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
270 void ms_AVdecoder_set_width(MSAVDecoder *av,gint w)
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
271 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
272 av->av_context.width=av->width=w;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
273 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
274
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
275 void ms_AVdecoder_set_height(MSAVDecoder *av,gint h)
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
276 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
277 av->av_context.height=av->height=h;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
278 }