1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004 orx |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | ### File Specific: |
---|
12 | main-programmer: David Hasenfratz, Stephan Lienhard |
---|
13 | co-programmer: |
---|
14 | */ |
---|
15 | |
---|
16 | |
---|
17 | |
---|
18 | /* this is for debug output. It just says, that all calls to PRINT() belong to the DEBUG_MODULE_MEDIA module |
---|
19 | For more information refere to https://www.orxonox.net/cgi-bin/trac.cgi/wiki/DebugOutput |
---|
20 | */ |
---|
21 | #define DEBUG_MODULE_MEDIA |
---|
22 | |
---|
23 | |
---|
24 | /* include your own header */ |
---|
25 | #include "media_container.h" |
---|
26 | |
---|
27 | /* header for debug output */ |
---|
28 | #include "debug.h" |
---|
29 | |
---|
30 | |
---|
31 | /** |
---|
32 | * Default constructor |
---|
33 | */ |
---|
34 | MediaContainer::MediaContainer(const char* filename) |
---|
35 | { |
---|
36 | /* set the class id for the base object */ |
---|
37 | this->setClassID(CL_MEDIA_CONTAINER, "MediaContainer"); |
---|
38 | |
---|
39 | /* register all formats and codecs */ |
---|
40 | av_register_all(); |
---|
41 | |
---|
42 | current_frame = 0; |
---|
43 | num_frames = 0; |
---|
44 | |
---|
45 | if (filename != NULL) |
---|
46 | this->loadMedia(filename); |
---|
47 | |
---|
48 | } |
---|
49 | |
---|
50 | /** |
---|
51 | * Default destructor |
---|
52 | */ |
---|
53 | MediaContainer::~MediaContainer() |
---|
54 | { |
---|
55 | //av_free(pFrameRGB); |
---|
56 | |
---|
57 | /* Free the frame */ |
---|
58 | av_free(frame); |
---|
59 | |
---|
60 | /* Close the codec */ |
---|
61 | avcodec_close(codec_context); |
---|
62 | |
---|
63 | /* Close the video file */ |
---|
64 | av_close_input_file(format_context); |
---|
65 | |
---|
66 | } |
---|
67 | |
---|
68 | /*GLuint MediaContainer::getFrame(int frame_number) |
---|
69 | { |
---|
70 | |
---|
71 | } |
---|
72 | |
---|
73 | GLuint MediaContainer::getNextFrame() |
---|
74 | { |
---|
75 | |
---|
76 | }*/ |
---|
77 | |
---|
78 | SDL_Surface* MediaContainer::getFrame(int frame_number) |
---|
79 | { |
---|
80 | SDL_Surface* frame; |
---|
81 | |
---|
82 | |
---|
83 | return frame; |
---|
84 | } |
---|
85 | |
---|
86 | SDL_Surface* MediaContainer::getNextFrame() |
---|
87 | { |
---|
88 | current_frame++; |
---|
89 | return this->getFrame(current_frame); |
---|
90 | } |
---|
91 | |
---|
92 | void MediaContainer::loadMedia(const char* filename) |
---|
93 | { |
---|
94 | /* Open video file */ |
---|
95 | if (av_open_input_file(&format_context, filename, NULL, 0, NULL) !=0 ) |
---|
96 | PRINTF(1)("Could not open %s\n", filename); |
---|
97 | |
---|
98 | /* Retrieve stream information */ |
---|
99 | if (av_find_stream_info(format_context) < 0) |
---|
100 | PRINTF(1)("Could not find stream information in %s\n", filename); |
---|
101 | |
---|
102 | // Dump information about file onto standard error |
---|
103 | //dump_format(pFormatCtx, 0, argv[1], false); |
---|
104 | |
---|
105 | /* Find the first video stream and take it */ |
---|
106 | video_stream = -1; |
---|
107 | for(int i = 0; i < format_context->nb_streams; i++) |
---|
108 | { |
---|
109 | // NOTE: different code for the 0.4.9-pre1 release of ffmpeg (tardis) |
---|
110 | // if(format_context->streams[i]->codec.codec_type == CODEC_TYPE_VIDEO) |
---|
111 | if(format_context->streams[i]->codec->codec_type == CODEC_TYPE_VIDEO) |
---|
112 | { |
---|
113 | video_stream = i; |
---|
114 | break; |
---|
115 | } |
---|
116 | } |
---|
117 | |
---|
118 | if(video_stream == -1) |
---|
119 | PRINTF(1)("Could not find a video stream in %s\n", filename); |
---|
120 | |
---|
121 | /* Get a pointer to the codec context for the video stream */ |
---|
122 | // NOTE: different code for the 0.4.9-pre1 release of ffmpeg (tardis) |
---|
123 | // codec_context = &format_context->streams[video_stream]->codec; |
---|
124 | codec_context = format_context->streams[video_stream]->codec; |
---|
125 | |
---|
126 | /* Find the decoder for the video stream */ |
---|
127 | codec = avcodec_find_decoder(codec_context->codec_id); |
---|
128 | if (codec == NULL) |
---|
129 | PRINTF(1)("Could not find codec\n"); |
---|
130 | |
---|
131 | /* Open codec */ |
---|
132 | if (avcodec_open(codec_context, codec) < 0) |
---|
133 | PRINTF(1)("Could not open codec\n"); |
---|
134 | |
---|
135 | } |
---|
136 | |
---|
137 | int MediaContainer::getHeight() |
---|
138 | { |
---|
139 | |
---|
140 | } |
---|
141 | |
---|
142 | int MediaContainer::getWidth() |
---|
143 | { |
---|
144 | |
---|
145 | } |
---|
146 | |
---|
147 | int MediaContainer::getFrameRate() |
---|
148 | { |
---|
149 | |
---|
150 | } |
---|
151 | |
---|
152 | void MediaContainer::getStream(/* stream */) |
---|
153 | { |
---|
154 | |
---|
155 | } |
---|