Coin Logo Coin3D is Free Software,
published under the BSD 3-clause license.
https://coin3d.github.io
https://www.kongsberg.com/en/kogt/
movie.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) Kongsberg Oil & Gas Technologies
3  *
4  * Permission to use, copy, modify, and distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 /*
18  * Note 20020923 thammer:
19  * movie.c should probably be rewritten to use stream.c.
20  * If you are considering modifying movie.c, please discuss it
21  * with coin-support@sim.no first.
22  */
23 
24 #include <assert.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif /* HAVE_CONFIG_H */
31 #include <simage.h>
32 #include <simage_private.h>
33 #include <string.h>
34 
35 #ifdef SIMAGE_MPEG2ENC_SUPPORT
36 #include "../mpeg2enc/api.h"
37 #endif /* SIMAGE_MPEG2ENC_SUPPORT */
38 
39 #ifdef SIMAGE_AVIENC_SUPPORT
40 #include "simage_avi.h"
41 #endif /* SIMAGE_AVIENC_SUPPORT */
42 
44  char * filename;
45 
51 
53 };
54 
59 
61 };
62 
67 
69 };
70 
71 // FIXME: convert access to these variables into the singleton
72 // pattern. 20010917 mortene.
75 
76 static void
78 {
79  static int first = 1;
80  if (first) {
81  /* none yet */
82  first = 0;
83  }
84 }
85 
86 static void
88 {
89  static int first = 1;
90  if (first) {
91 #ifdef SIMAGE_MPEG2ENC_SUPPORT
92  s_movie_exporter_add(mpeg2enc_movie_create,
93  mpeg2enc_movie_put,
94  mpeg2enc_movie_close);
95 #endif
96 #ifdef SIMAGE_AVIENC_SUPPORT
100 #endif
101  first = 0;
102  }
103 }
104 
105 s_movie *
106 s_movie_open(const char * filename)
107 {
108  struct simage_movie_importer * imp;
109  s_movie * movie = (s_movie*) malloc(sizeof(s_movie));
110  movie->params = NULL;
111  movie->filename = NULL;
112 
114 
115  imp = importers;
116  while (imp) {
117  if (imp->open(filename, movie)) break;
118  imp = imp->next;
119  }
120  if (imp == NULL) {
121  free((void*)movie);
122  return NULL;
123  }
124 
125  movie->filename = (char*) malloc(strlen(filename)+1);
126  strcpy(movie->filename, filename);
127  movie->open = imp->open;
128  movie->get = imp->get;
129  movie->close = imp->close;
130 
131  return movie;
132 }
133 
134 s_movie *
135 s_movie_create(const char * filename, s_params * params /* | NULL */)
136 {
137  struct simage_movie_exporter * exp;
138  s_movie * movie = (s_movie*) malloc(sizeof(s_movie));
139  movie->params = NULL;
140  movie->filename = NULL;
141 
143 
144  exp = exporters;
145  while (exp) {
146  if (exp->create(filename, movie, params)) break;
147  exp = exp->next;
148  }
149  if (exp == NULL) {
150  free((void*) movie);
151  return NULL;
152  }
153 
154  movie->filename = (char*) malloc(strlen(filename)+1);
155  movie->create = exp->create;
156  movie->put = exp->put;
157  movie->close = exp->close;
158  strcpy(movie->filename, filename);
159  return movie;
160 }
161 
162 s_image *
163 s_movie_get_image(s_movie * movie, s_image * prealloc, s_params * params)
164 {
165  return movie->get(movie, prealloc, params);
166 }
167 
168 int
170  s_params * params)
171 {
172  return movie->put(movie, image, params);
173 }
174 
175 void
177 {
178  movie->close(movie);
179 }
180 
181 void
183 {
184  if (movie->params) s_params_destroy(movie->params);
185  if (movie->filename) free((void*) movie->filename);
186  free((void*) movie);
187 }
188 
189 s_params *
191 {
192  if (movie->params == NULL) {
193  movie->params = s_params_create();
194  }
195  return movie->params;
196 }
197 
198 void
200  s_movie_get_func * get,
202 {
203  struct simage_movie_importer * last, * imp = importers;
204  last = NULL;
205  while (imp) {
206  last = imp;
207  imp = imp->next;
208  }
209  imp = (struct simage_movie_importer*) malloc(sizeof(struct simage_movie_importer));
210  imp->open = open;
211  imp->get = get;
212  imp->close = close;
213  imp->next = NULL;
214 
215  if (last == NULL) {
216  importers = imp;
217  }
218  else last->next = imp;
219 }
220 
221 void
223  s_movie_put_func * put,
225 {
226  struct simage_movie_exporter * last, * exp = exporters;
227  last = NULL;
228  while (exp) {
229  last = exp;
230  exp = exp->next;
231  }
232  exp = (struct simage_movie_exporter*) malloc(sizeof(struct simage_movie_exporter));
233  exp->create = create;
234  exp->put = put;
235  exp->close = close;
236  exp->next = NULL;
237 
238  if (last == NULL) {
239  exporters = exp;
240  }
241  else last->next = exp;
242 }
s_params * s_movie_params(s_movie *movie)
Definition: movie.c:190
void s_movie_exporter_add(s_movie_create_func *create, s_movie_put_func *put, s_movie_close_func *close)
Definition: movie.c:222
static struct simage_movie_exporter * exporters
Definition: movie.c:74
void s_params_destroy(s_params *params)
Definition: params.c:57
static void add_internal_exporters(void)
Definition: movie.c:87
int avienc_movie_create(const char *filename, s_movie *movie, s_params *params)
struct simage_movie_importer * next
Definition: movie.c:60
struct simage_movie_exporter * next
Definition: movie.c:68
s_movie_open_func * open
Definition: movie.c:56
s_params * params
Definition: movie.c:52
char * filename
Definition: movie.c:44
void s_movie_close_func(s_movie *)
Definition: simage.h:295
int s_movie_create_func(const char *, s_movie *, s_params *)
Definition: simage.h:292
s_movie_put_func * put
Definition: movie.c:65
s_movie_close_func * close
Definition: movie.c:50
s_movie * s_movie_create(const char *filename, s_params *params)
Definition: movie.c:135
s_movie_get_func * get
Definition: movie.c:48
void avienc_movie_close(s_movie *movie)
void s_movie_close(s_movie *movie)
Definition: movie.c:176
Windows specific information.
s_movie_put_func * put
Definition: movie.c:49
s_movie_open_func * open
Definition: movie.c:46
int s_movie_put_image(s_movie *movie, s_image *image, s_params *params)
Definition: movie.c:169
s_movie_get_func * get
Definition: movie.c:57
int s_movie_put_func(s_movie *, s_image *, s_params *)
Definition: simage.h:294
s_movie_close_func * close
Definition: movie.c:66
s_movie_create_func * create
Definition: movie.c:47
void s_movie_destroy(s_movie *movie)
Definition: movie.c:182
void s_movie_importer_add(s_movie_open_func *open, s_movie_get_func *get, s_movie_close_func *close)
Definition: movie.c:199
static void add_internal_importers(void)
Definition: movie.c:77
s_movie * s_movie_open(const char *filename)
Definition: movie.c:106
static struct simage_movie_importer * importers
Definition: movie.c:73
s_image * s_movie_get_func(s_movie *, s_image *, s_params *)
Definition: simage.h:293
int avienc_movie_put(s_movie *movie, s_image *image, s_params *params)
s_movie_close_func * close
Definition: movie.c:58
s_image * s_movie_get_image(s_movie *movie, s_image *prealloc, s_params *params)
Definition: movie.c:163
s_params * s_params_create(void)
Definition: params.c:49
s_movie_create_func * create
Definition: movie.c:64
int s_movie_open_func(const char *, s_movie *)
Definition: simage.h:291