~ubuntu-branches/ubuntu/vivid/linphone/vivid

« back to all changes in this revision

Viewing changes to mediastreamer/msxine.c

  • Committer: Bazaar Package Importer
  • Author(s): Samuel Mimram
  • Date: 2006-11-15 10:34:50 UTC
  • mfrom: (1.2.1 upstream) (2.1.8 feisty)
  • Revision ID: james.westby@ubuntu.com-20061115103450-qgafwcks2lkhctlj
* New upstream release.
* Enable video support.
* Fix mismatched #endif in mscommon.h, closes: #398307.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
  The mediastreamer library aims at providing modular media processing and I/O
3
 
        for linphone, but also for any telephony application.
4
 
  Copyright (C) 2001  Simon MORLAT simon.morlat@linphone.org
5
 
                                                                                
6
 
  This library is free software; you can redistribute it and/or
7
 
  modify it under the terms of the GNU Lesser General Public
8
 
  License as published by the Free Software Foundation; either
9
 
  version 2.1 of the License, or (at your option) any later version.
10
 
 
11
 
  This library is distributed in the hope that it will be useful,
12
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 
  Lesser General Public License for more details.
15
 
 
16
 
  You should have received a copy of the GNU Lesser General Public
17
 
  License along with this library; if not, write to the Free Software
18
 
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
 
*/
20
 
 
21
 
#include "msxine.h"
22
 
#include "stdlib.h"
23
 
 
24
 
 
25
 
static MSXineClass *ms_xine_class=NULL;
26
 
 
27
 
static void change_window_size(void *user_data,
28
 
                                         int video_width, int video_height,
29
 
                                         int *dest_x, int *dest_y,
30
 
                                         int *dest_height, int *dest_width)
31
 
{
32
 
        MSXine *obj=(MSXine*)user_data;
33
 
        XLockDisplay(obj->vis.display);
34
 
        g_message("entering change window size!!!!");
35
 
        g_message("video_width=%i, video_height=%i",video_width,video_height);
36
 
        sleep(1);
37
 
        fflush(NULL);
38
 
        XUnlockDisplay(obj->vis.display);
39
 
        
40
 
}
41
 
 
42
 
void calc_dest_size (void *this,
43
 
                                  int video_width, int video_height,
44
 
                                  int *dest_width, int *dest_height)  {
45
 
        g_message("entering video_window_calc_dest_size() !");
46
 
        *dest_width=video_width;
47
 
        *dest_height=video_height;
48
 
}
49
 
void ms_xine_init(MSXine *obj)
50
 
{
51
 
        MSXineClass *klass=MS_XINE_CLASS(MS_FILTER(obj)->klass);
52
 
        double res_h,res_v;
53
 
        XSetWindowAttributes att;
54
 
        ao_driver_t *ao_driver;
55
 
        XGCValues             xgcv;
56
 
 
57
 
        
58
 
        ms_filter_init(MS_FILTER(obj));
59
 
        MS_FILTER(obj)->inqueues=obj->input;
60
 
        memset(&obj->vis,0,sizeof(x11_visual_t));
61
 
        /* create an X11 window */
62
 
        obj->vis.display=XOpenDisplay(NULL);
63
 
        obj->vis.screen=DefaultScreen(obj->vis.display);
64
 
        
65
 
        res_h                 = (DisplayWidth  (obj->vis.display, obj->vis.screen)*1000 
66
 
                           / DisplayWidthMM (obj->vis.display, obj->vis.screen));
67
 
        res_v                 = (DisplayHeight (obj->vis.display, obj->vis.screen)*1000
68
 
                           / DisplayHeightMM (obj->vis.display, obj->vis.screen));
69
 
        obj->vis.display_ratio     = res_h / res_v;
70
 
        if (fabs(obj->vis.display_ratio - 1.0) < 0.01) {
71
 
    /*
72
 
     * we have a display with *almost* square pixels (<1% error),
73
 
     * to avoid time consuming software scaling in video_out_xshm,
74
 
     * correct this to the exact value of 1.0 and pretend we have
75
 
     * perfect square pixels.
76
 
     */
77
 
                obj->vis.display_ratio   = 1.0;
78
 
        }
79
 
        
80
 
        att.colormap=DefaultColormap(obj->vis.display,obj->vis.screen);
81
 
        att.background_pixel  = BlackPixel(obj->vis.display,obj->vis.screen);
82
 
    att.border_pixel      = BlackPixel(obj->vis.display,obj->vis.screen);
83
 
        obj->vis.d=XCreateWindow(obj->vis.display,RootWindow(obj->vis.display,obj->vis.screen),0,0,1000,800,0,
84
 
                                                DefaultDepth(obj->vis.display,obj->vis.screen),CopyFromParent,
85
 
                                                DefaultVisual(obj->vis.display,obj->vis.screen),
86
 
                                                CWColormap | CWBackPixel  | CWBorderPixel,
87
 
                                                &att);
88
 
        XMapWindow(obj->vis.display,obj->vis.d);
89
 
        XSync(obj->vis.display,False);
90
 
        XSetStandardProperties(obj->vis.display, obj->vis.d, 
91
 
                           "Linphone video display", "Linphone video display", None, NULL, 0, 0);
92
 
        XCreateGC(obj->vis.display, obj->vis.d, 0L, &xgcv);
93
 
        
94
 
        //XMapRaised(obj->vis.display,obj->vis.d);
95
 
        //sleep(1);
96
 
        //XFlush(obj->vis.display);
97
 
        
98
 
        /* select the first availlable output plugin type*/
99
 
        obj->vo_driver=xine_load_video_output_plugin(klass->config,
100
 
                                                        klass->video_plugins[0],
101
 
                                                        VISUAL_TYPE_X11,
102
 
                                                        &obj->vis);
103
 
        if (obj->vo_driver==NULL){
104
 
                g_error("Could not load a xine output plugin.");
105
 
        }
106
 
        else g_message("New vo driver %x created.",obj->vo_driver);
107
 
        ao_driver=xine_load_audio_output_plugin(klass->config,"esd");
108
 
        if (ao_driver==NULL) g_message("Could not load audio output plugin");
109
 
                
110
 
        /* set some callbacks */
111
 
        obj->vis.user_data=(void*)obj;
112
 
        obj->vis.request_dest_size=change_window_size;
113
 
        obj->vis.calc_dest_size=calc_dest_size;
114
 
        
115
 
        /* initializing a xine engine*/
116
 
        obj->engine=xine_init(obj->vo_driver,ao_driver,klass->config);
117
 
        if (obj->engine==NULL){
118
 
                g_error("Could not create a new xine engine");
119
 
        }
120
 
        
121
 
        obj->vo_driver->gui_data_exchange (obj->vo_driver,
122
 
                                          GUI_DATA_EX_DRAWABLE_CHANGED, 
123
 
                                          (void*)obj->vis.d);
124
 
}
125
 
 
126
 
void ms_xine_class_init(MSXineClass *klass)
127
 
{
128
 
        int i;
129
 
        
130
 
        ms_filter_class_init(MS_FILTER_CLASS(klass));
131
 
        MS_FILTER_CLASS(klass)->max_qinputs=1;
132
 
        MS_FILTER_CLASS(klass)->destroy=(MSFilterDestroyFunc)ms_xine_destroy;
133
 
        /* read xine config file */
134
 
        klass->config=config_file_init(NULL);
135
 
        if (klass->config==NULL){
136
 
                g_error("Could not read xine config file");
137
 
        }
138
 
        /* list availlable video output plugins */
139
 
        klass->video_plugins=xine_list_video_output_plugins(VISUAL_TYPE_X11);
140
 
        g_message("Xine video plugins for X11 are:");
141
 
        i=0;
142
 
        while (klass->video_plugins[i]!=NULL)
143
 
        {
144
 
                g_message("\t- %s",klass->video_plugins[i]);
145
 
                i++;
146
 
        }
147
 
        
148
 
}
149
 
 
150
 
MSFilter * ms_xine_new()
151
 
{
152
 
        MSXine *obj=g_malloc(sizeof(MSXine));
153
 
        
154
 
        if (ms_xine_class==NULL)
155
 
        {
156
 
                ms_xine_class=g_malloc(sizeof(MSXineClass));
157
 
                ms_xine_class_init(ms_xine_class);
158
 
        }
159
 
        MS_FILTER(obj)->klass=MS_FILTER_CLASS(ms_xine_class);
160
 
        ms_xine_init(obj);
161
 
        return MS_FILTER(obj);
162
 
}
163
 
 
164
 
void ms_xine_start(MSXine *obj)
165
 
{
166
 
        xine_play(obj->engine,
167
 
        "file://cdrom/Videos/(smr)shrek-ts(1of2).avi",
168
 
        0,0);
169
 
}
170
 
 
171
 
void ms_xine_uninit(MSXine *obj)
172
 
{
173
 
        xine_exit(obj->engine);
174
 
        free(obj->vo_driver);
175
 
        XDestroyWindow(obj->vis.display,obj->vis.d);
176
 
}
177
 
 
178
 
void ms_xine_stop(MSXine *obj)
179
 
{
180
 
        xine_stop(obj->engine);
181
 
}
182
 
 
183
 
 
184
 
void ms_xine_destroy(MSXine *obj)
185
 
{
186
 
        ms_xine_uninit(obj);
187
 
        g_free(obj);
188
 
}
189