- Timestamp:
- Jan 11, 2006, 4:01:06 PM (19 years ago)
- Location:
- branches/avi_play_merge
- Files:
-
- 9 edited
- 5 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/avi_play_merge/config.h.in
r6271 r6486 10 10 #undef HAVE_AL_AL_H 11 11 12 /* Define to 1 if you have the <avcodec.h> header file. */ 13 #undef HAVE_AVCODEC_H 14 15 /* Define to 1 if you have the <avformat.h> header file. */ 16 #undef HAVE_AVFORMAT_H 17 12 18 /* Define to 1 if you have the `bzero' function. */ 13 19 #undef HAVE_BZERO … … 15 21 /* if we have CURL */ 16 22 #undef HAVE_CURL 23 24 /* Define to 1 if you have the <ffmpeg/avcodec.h> header file. */ 25 #undef HAVE_FFMPEG_AVCODEC_H 26 27 /* Define to 1 if you have the <ffmpeg/avformat.h> header file. */ 28 #undef HAVE_FFMPEG_AVFORMAT_H 17 29 18 30 /* Define to 1 if you have the <GL/glew.h> header file. */ -
branches/avi_play_merge/configure.ac
r6274 r6486 1 1 2 ########################################################################## 2 3 # orxonox - the future of 3D-vertical-scrollers # … … 522 523 AX_CHECK_REQUIRED_HEADER_LIB([vorbis/codec.h], [vorbis], [main],,, [http://www.xiph.org/ogg/vorbis/index.html]) 523 524 AX_CHECK_REQUIRED_HEADER_LIB([vorbis/vorbisfile.h], [vorbisfile], [main],,, [http://www.xiph.org/ogg/vorbis/index.html]) 525 526 #--------# 527 # FFmpeg # 528 #--------# 529 # checking for FFmpeg-headers 530 AC_CHECK_HEADERS([avformat.h] ,, 531 [AC_CHECK_HEADERS([ffmpeg/avformat.h] ,,AC_MSG_ERROR([cannot find FFmpeg header.])])) 532 # checking for ffmpeg-lib 533 AC_CHECK_LIB([avformat], [main], [FOUND_avformat=yes; LIBS="$LIBS -lavformat"]) 534 if test x$FOUND_avformat != xyes ; then 535 echo "------------------" 536 echo "avformat library not found." 537 echo "please install the FFmpeg library, which can be found at http://ffmpeg.sourceforge.net" 538 echo "------------------" 539 exit -1 540 fi 541 AC_CHECK_HEADERS([avcodec.h] ,, 542 [AC_CHECK_HEADERS([ffmpeg/avcodec.h] ,,AC_MSG_ERROR([cannot find FFmpeg header.])])) 543 AC_CHECK_LIB([avcodec], [main], [FOUND_avcodec=yes; LIBS="$LIBS -lavcodec"]) 544 if test x$FOUND_avcodec != xyes ; then 545 echo "------------------" 546 echo "avcodec library not found." 547 echo "please install the FFmpeg library, which can be found at http://ffmpeg.sourceforge.net" 548 echo "------------------" 549 exit -1 550 fi 551 AC_CHECK_LIB([avutil], [main], [FOUND_avutil=yes; LIBS="$LIBS -lavutil"]) 552 553 AC_CHECK_LIB([theora], [main], [FOUND_theora=yes; LIBS="$LIBS -ltheora"]) 554 555 AC_CHECK_LIB([dts], [main], [FOUND_dts=yes; LIBS="$LIBS -ldts"]) 556 557 AC_CHECK_LIB([gsm], [main], [FOUND_gsm=yes; LIBS="$LIBS -lgsm"]) 558 559 AC_CHECK_LIB([dc1394_control], [main], [FOUND_dc1394_control=yes; LIBS="$LIBS -ldc1394_control"]) 560 561 AC_CHECK_LIB([vorbisenc], [main], [FOUND_vorbisenc=yes; LIBS="$LIBS -lvorbisenc"]) 524 562 525 563 #---------# -
branches/avi_play_merge/src/defs/class_id.h
r6455 r6486 226 226 CL_TEXTURE_SEQUENCE = 0x00004805, 227 227 CL_OBJ_MODEL = 0x00000807, 228 229 CL_MOVIE_PLAYER = 0x00000805, 230 CL_MEDIA_CONTAINER = 0x00000806, 228 231 CL_PROMITIVE_MODEL = 0x00000808, 229 232 CL_MD2Model = 0x00000809, -
branches/avi_play_merge/src/lib/graphics/importer/Makefile.am
r6455 r6486 14 14 texture.cc \ 15 15 texture_sequence.cc \ 16 height_map.cc 16 height_map.cc \ 17 media_container.cc \ 18 movie_player.cc 17 19 18 20 libtc_a_SOURCES = tc.cc … … 32 34 height_map.h \ 33 35 anorms.h \ 34 anormtab.h 36 anormtab.h \ 37 media_container.h \ 38 movie_player.h -
branches/avi_play_merge/src/lib/graphics/importer/media_container.cc
r5960 r6486 34 34 MediaContainer::MediaContainer(const char* filename) 35 35 { 36 36 // set the class id for the base object 37 this->setClassID(CL_MEDIA_CONTAINER, "MediaContainer"); 38 39 fps = 0; 40 41 if (filename != NULL) 42 { 43 if(!this->loadMedia(filename)) 44 PRINTF(1)("MediaContainer::loadMedia() failed for %s\n", filename); 45 } 46 } 47 48 MediaContainer::MediaContainer() 49 { 50 // set the class id for the base object 51 this->setClassID(CL_MEDIA_CONTAINER, "MediaContainer"); 52 53 fps = 0; 37 54 } 38 55 … … 42 59 MediaContainer::~MediaContainer() 43 60 { 44 45 } 46 47 GLuint MediaContainer::getFrame(int frame_number) 48 { 49 50 } 61 if (glIsTexture(texture)) 62 glDeleteTextures(1, &texture); 63 64 // Free the RGB image 65 delete [] buffer; 66 av_free(RGB_frame); 67 68 // Free the frame 69 av_free(frame); 70 71 // Close the codec 72 avcodec_close(codec_context); 73 74 // Close the video file 75 av_close_input_file(format_context); 76 } 77 78 bool MediaContainer::loadMedia(const char* filename) 79 { 80 // register all formats and codecs 81 av_register_all(); 82 83 // Open video file 84 if (av_open_input_file(&format_context, filename, NULL, 0, NULL) !=0 ) 85 { 86 PRINTF(1)("Could not open %s\n", filename); 87 return false; 88 } 89 90 // Retrieve stream information 91 if (av_find_stream_info(format_context) < 0) 92 { 93 PRINTF(1)("Could not find stream information in %s\n", filename); 94 return false; 95 } 96 97 // Find the first video stream and take it 98 video_stream = av_find_default_stream_index(format_context); 99 100 if(video_stream == -1) 101 { 102 PRINTF(1)("Could not find a video stream in %s\n", filename); 103 return false; 104 } 105 106 // Get a pointer to the codec context for the video stream 107 // NOTE: different code for the 0.4.9-pre1 release of ffmpeg (tardis) 108 // codec_context = &format_context->streams[video_stream]->codec; 109 codec_context = format_context->streams[video_stream]->codec; 110 111 // Find the decoder for the video stream 112 codec = avcodec_find_decoder(codec_context->codec_id); 113 if (codec == NULL) 114 { 115 PRINTF(1)("Could not find codec\n"); 116 return false; 117 } 118 119 // Open codec 120 if (avcodec_open(codec_context, codec) < 0) 121 { 122 PRINTF(1)("Could not open codec\n"); 123 return false; 124 } 125 126 // Allocate video frame 127 frame = avcodec_alloc_frame(); 128 RGB_frame = avcodec_alloc_frame(); 129 130 // Determine required buffer size and allocate buffer 131 num_bytes = avpicture_get_size(PIX_FMT_RGB24, codec_context->width, codec_context->height); 132 buffer=new uint8_t[num_bytes]; 133 134 // data buffer for the texture 135 data = new uint8_t[codec_context->width*codec_context->height*3*sizeof(uint8_t)]; 136 137 // Assign appropriate parts of buffer to image planes in RGB_frame 138 avpicture_fill((AVPicture *)RGB_frame, buffer, PIX_FMT_RGB24, codec_context->width, codec_context->height); 139 140 // Calculate fps 141 fps = av_q2d(format_context->streams[video_stream]->r_frame_rate); 142 // NOTE: fix this fps problem!! 143 if(fps < 0 || fps > 1000) 144 fps = 30; 145 146 // read the frames and save them in a sequence as textures 147 this->loadFrames(); 148 149 return true; 150 } 151 152 double MediaContainer::getFPS() 153 { 154 return this->fps; 155 } 156 157 void MediaContainer::loadFrames() 158 { 159 // empty texture list 160 this->clearLists(); 161 162 // go to the begin of the video 163 av_seek_frame(format_context, video_stream, 0, AVSEEK_FLAG_BACKWARD); 164 165 // get all the frames and save them in the sequence 166 while(this->addFrame(this->getNextFrame()) != NULL); 167 } 168 51 169 52 170 GLuint MediaContainer::getNextFrame() 53 171 { 54 172 55 } 56 57 void MediaContainer::loadMedia(char* filename) 58 { 59 60 } 61 62 int MediaContainer::getHeight() 63 { 64 65 } 66 67 int MediaContainer::getWidth() 68 { 69 70 } 71 72 int MediaContainer::getFrameRate() 73 { 74 75 } 76 77 void MediaContainer::getStream(/* stream */) 78 { 79 80 } 173 // get next frame 174 if(av_read_frame(format_context, &packet) >= 0) 175 { 176 // Is this a packet from the video stream? 177 if(packet.stream_index == video_stream) 178 { 179 int frame_finished; 180 // Decode video frame 181 avcodec_decode_video(codec_context, frame, &frame_finished, 182 packet.data, packet.size); 183 184 // Free the packet that was allocated by av_read_frame 185 av_free_packet(&packet); 186 187 // Did we get a video frame? 188 if(frame_finished) 189 { 190 // Conversion from YUV to RGB 191 // Most codecs return images in YUV 420 format 192 // (one luminance and two chrominance channels, with the chrominance 193 // channels samples at half the spatial resolution of the luminance channel) 194 img_convert((AVPicture*)RGB_frame, PIX_FMT_RGB24, (AVPicture*)frame, 195 codec_context->pix_fmt, codec_context->width, codec_context->height); 196 197 for(int i = 0; i < codec_context->height; i++) 198 memcpy(&data[i*codec_context->width*3], 199 ((AVPicture*)RGB_frame)->data[0]+i * 200 ((AVPicture*)RGB_frame)->linesize[0], 201 codec_context->width*sizeof(uint8_t)*3); 202 203 // Create an OpenGL texture 204 glGenTextures(1, &texture); 205 glBindTexture(GL_TEXTURE_2D, texture); 206 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 207 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 208 // create the texture 209 glTexImage2D(GL_TEXTURE_2D, 210 0, 211 GL_RGB, 212 codec_context->width, codec_context->height, 213 0, 214 GL_RGB, 215 GL_UNSIGNED_BYTE, 216 data); 217 // build the MipMaps 218 gluBuild2DMipmaps(GL_TEXTURE_2D, 219 GL_RGB, 220 codec_context->width, 221 codec_context->height, 222 GL_RGB, 223 GL_UNSIGNED_BYTE, 224 data); 225 glBindTexture(GL_TEXTURE_2D, 0); 226 227 return texture; 228 } 229 else 230 { 231 av_free_packet(&packet); 232 return this->getNextFrame(); 233 } 234 } 235 else 236 { 237 av_free_packet(&packet); 238 return this->getNextFrame(); 239 } 240 } 241 else 242 return NULL; 243 } -
branches/avi_play_merge/src/lib/graphics/importer/media_container.h
r5960 r6486 8 8 #define _MEDIA_CONTAINER 9 9 10 /* FFmpeg */ 11 //#include "ffmpeg/avformat.h" 10 #include <SDL.h> 12 11 13 12 #ifdef HAVE_AVFORMAT_H … … 17 16 #endif 18 17 18 /* include base_object.h since all classes are derived from this one */ 19 #include "base_object.h" 20 #include "texture_sequence.h" 21 19 22 #include "glincl.h" 20 23 21 /* include base_object.h since all classes are derived from this one */ 22 #include "base_object.h" 23 24 /* using namespace std is default, this needs to be here */ 25 using namespace std; 26 27 class MediaContainer : public BaseObject 24 class MediaContainer : public TextureSequence 28 25 { 29 26 30 27 private: 31 28 32 char* filename; 33 int current_frame; 29 AVFormatContext* format_context; 30 AVCodecContext* codec_context; 31 AVCodec* codec; 32 AVFrame* frame; 33 AVPacket packet; 34 AVFrame* RGB_frame; 34 35 35 AVFormatContext* format_context; 36 AVCodecContext* codec_context; 37 AVCodec* codec; 38 AVFrame* frame; 39 AVPacket packet; 40 41 int num_bytes; 42 int video_stream; 36 GLuint texture; 37 uint8_t* data; 38 uint8_t* buffer; 39 int num_bytes; 40 int video_stream; 41 double fps; 43 42 44 43 public: 45 44 46 45 MediaContainer(const char* filename); 46 MediaContainer(); 47 47 ~MediaContainer(); 48 48 49 GLuint getFrame(int frame_number);50 GLuint getNextFrame();51 void loadMedia(char* filename); 52 53 int getHeight(); 54 int getWidth(); 55 int getFrameRate(); 56 void getStream(/* stream */);49 bool loadMedia(const char* filename); 50 void loadFrames(); 51 52 double getFPS(); 53 54 private: 55 56 GLuint getNextFrame(); 57 57 58 58 }; 59 59 60 60 61 62 61 #endif /* _MEDIA_CONTAINER */ -
branches/avi_play_merge/src/lib/graphics/importer/movie_player.cc
r5960 r6486 10 10 11 11 ### File Specific: 12 main-programmer: David Hasenfratz , Stephan Lienhard12 main-programmer: David Hasenfratz 13 13 co-programmer: 14 14 */ … … 22 22 23 23 24 / * include your own header */24 // include your own header 25 25 #include "movie_player.h" 26 26 27 / * header for debug output */27 // header for debug output 28 28 #include "debug.h" 29 29 30 30 31 /**32 * Default constructor33 */34 31 MoviePlayer::MoviePlayer(const char* filename) 35 32 { 36 37 } 38 39 /** 40 * Default destructor 41 */ 33 this->init(); 34 35 if (filename != NULL) 36 { 37 if(!this->loadMovie(filename)) 38 PRINTF(1)("MoviePlayer::loadMovie() failes for %s\n", filename); 39 } 40 } 41 42 MoviePlayer::MoviePlayer() 43 { 44 this->init(); 45 } 46 42 47 MoviePlayer::~MoviePlayer() 43 48 { 44 45 } 46 47 void MoviePlayer::start(unsigned int start_frame) 48 { 49 49 delete material; 50 delete model; 51 52 if (glIsTexture(texture)) 53 glDeleteTextures(1, &texture); 54 55 // Free the RGB image 56 delete [] buffer; 57 av_free(RGB_frame); 58 59 // Free the frame 60 av_free(frame); 61 62 avcodec_default_free_buffers(codec_context); 63 64 // Close the codec 65 avcodec_close(codec_context); 66 67 // Close the video file 68 av_close_input_file(format_context); 69 } 70 71 void MoviePlayer::init() 72 { 73 // set the class id for the base object 74 this->setClassID(CL_MOVIE_PLAYER, "MoviePlayer"); 75 76 status = STOP; 77 timer = 0; 78 frame_number = 0; 79 loading = false; 80 81 material = new Material; 82 material->setDiffuseMap("maps/radialTransparency.png"); 83 84 model = new PrimitiveModel(PRIM_PLANE, 10.0); 85 86 LightManager* lightMan = LightManager::getInstance(); 87 lightMan->setAmbientColor(.1,.1,.1); 88 (new Light())->setAbsCoor(5.0, 10.0, 40.0); 89 (new Light())->setAbsCoor(-10, -20, -100); 90 } 91 92 bool MoviePlayer::loadMovie(const char* filename) 93 { 94 // register all formats and codecs 95 av_register_all(); 96 97 // Open video file 98 if (av_open_input_file(&format_context, filename, NULL, 0, NULL) !=0 ) 99 { 100 PRINTF(1)("Could not open %s\n", filename); 101 return false; 102 } 103 104 // Retrieve stream information 105 if (av_find_stream_info(format_context) < 0) 106 { 107 PRINTF(1)("Could not find stream information in %s\n", filename); 108 return false; 109 } 110 111 // Find the first video stream and take it 112 video_stream = av_find_default_stream_index(format_context); 113 114 if(video_stream == -1) 115 { 116 PRINTF(1)("Could not find a video stream in %s\n", filename); 117 return false; 118 } 119 120 // Get a pointer to the codec context for the video stream 121 // NOTE: different code for the 0.4.9-pre1 release of ffmpeg (tardis) 122 // codec_context = &format_context->streams[video_stream]->codec; 123 codec_context = format_context->streams[video_stream]->codec; 124 125 // Find the decoder for the video stream 126 codec = avcodec_find_decoder(codec_context->codec_id); 127 if (codec == NULL) 128 { 129 PRINTF(1)("Could not find codec\n"); 130 return false; 131 } 132 133 // Open codec 134 if (avcodec_open(codec_context, codec) < 0) 135 { 136 PRINTF(1)("Could not open codec\n"); 137 return false; 138 } 139 140 // Allocate video frame 141 frame = avcodec_alloc_frame(); 142 RGB_frame = avcodec_alloc_frame(); 143 144 // Determine required buffer size and allocate buffer 145 num_bytes = avpicture_get_size(PIX_FMT_RGB24, codec_context->width, codec_context->height); 146 buffer=new uint8_t[num_bytes]; 147 148 // Assign appropriate parts of buffer to image planes in RGB_frame 149 avpicture_fill((AVPicture *)RGB_frame, buffer, PIX_FMT_RGB24, codec_context->width, codec_context->height); 150 151 // data buffer for the texture 152 data = new uint8_t[codec_context->width*codec_context->height*3*sizeof(uint8_t)]; 153 154 // Calculate fps 155 fps = av_q2d(format_context->streams[video_stream]->r_frame_rate); 156 // NOTE: fix this fps problem!! 157 if(fps < 0 || fps > 1000) 158 fps = 30; 159 160 // duration 161 duration = format_context->duration / 1000000LL; 162 163 // create texture 164 glGenTextures(1, &texture); 165 glBindTexture(GL_TEXTURE_2D, texture); 166 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 167 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 168 glTexImage2D(GL_TEXTURE_2D, 169 0, 170 GL_RGB, 171 0, 0, 172 0, 173 GL_RGB, 174 GL_UNSIGNED_BYTE, 175 NULL); 176 glBindTexture(GL_TEXTURE_2D, 0); 177 178 loading = true; 179 return true; 180 } 181 182 void MoviePlayer::getNextFrame() 183 { 184 // get next frame 185 if(av_read_frame(format_context, &packet) >= 0) 186 { 187 // Is this a packet from the video stream? 188 if(packet.stream_index == video_stream) 189 { 190 int frame_finished; 191 // Decode video frame 192 avcodec_decode_video(codec_context, frame, &frame_finished, 193 packet.data, packet.size); 194 195 // Free the packet that was allocated by av_read_frame 196 av_free_packet(&packet); 197 198 // Did we get a video frame? 199 if(frame_finished) 200 { 201 frame_number++; 202 //PRINTF(0)("frame_number: %i\n", frame_number); 203 // Conversion from YUV to RGB 204 // Most codecs return images in YUV 420 format 205 // (one luminance and two chrominance channels, with the chrominance 206 // channels samples at half the spatial resolution of the luminance channel) 207 img_convert((AVPicture*)RGB_frame, PIX_FMT_RGB24, (AVPicture*)frame, 208 codec_context->pix_fmt, codec_context->width, codec_context->height); 209 210 for(int i = 0; i < codec_context->height; i++) 211 memcpy(&data[i*codec_context->width*3], ((AVPicture*)RGB_frame)->data[0]+i * 212 ((AVPicture*)RGB_frame)->linesize[0], 213 codec_context->width*sizeof(uint8_t)*3); 214 215 glBindTexture(GL_TEXTURE_2D, texture); 216 // update the texture 217 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 218 codec_context->width, codec_context->height, 219 GL_RGB, GL_UNSIGNED_BYTE, 220 data); 221 // build the MipMaps 222 gluBuild2DMipmaps(GL_TEXTURE_2D, 223 GL_RGB, 224 codec_context->width, 225 codec_context->height, 226 GL_RGB, 227 GL_UNSIGNED_BYTE, 228 data); 229 glBindTexture(GL_TEXTURE_2D, 0); 230 231 } 232 else 233 { 234 av_free_packet(&packet); 235 this->getNextFrame(); 236 } 237 } 238 else 239 { 240 av_free_packet(&packet); 241 this->getNextFrame(); 242 } 243 } 244 else 245 this->stop(); 246 } 247 248 void MoviePlayer::skipFrame(int frames) 249 { 250 251 while(frames != 0) 252 { 253 if(av_read_frame(format_context, &packet) < 0) 254 break; 255 if(packet.stream_index == video_stream) 256 { 257 int frame_finished; 258 // We have to decode the frame to not get ugly fragments 259 avcodec_decode_video(codec_context, frame, &frame_finished, 260 packet.data, packet.size); 261 262 // Did we get a video frame? 263 if(frame_finished) 264 { 265 frames--; 266 frame_number++; 267 } 268 } 269 av_free_packet(&packet); 270 } 271 272 this->getNextFrame(); 273 274 } 275 276 bool MoviePlayer::gotoFrame(int frames) 277 { 278 if(!loading) 279 { 280 PRINTF(0)("Load first the media file with loadMovie\n"); 281 return false; 282 } 283 284 int err; 285 // seek doesnt work for the first two frames 286 // you will get ugly fragments 287 if(frames < 2) 288 { 289 // go to the begin of the video 290 err = av_seek_frame(format_context, video_stream, 0, AVSEEK_FLAG_BACKWARD); 291 if(err < 0) 292 { 293 PRINTF(1)("Could not seek to frame 0\n"); 294 return false; 295 } 296 297 this->frame_number = 0; 298 } 299 else 300 { 301 // seeks to the nearest keyframe 302 // NOTE: there is only about every 5s a keyframe! 303 err = av_seek_frame(format_context, video_stream, frames, AVSEEK_FLAG_BACKWARD); 304 if(err < 0) 305 { 306 PRINTF(1)("Could not seek to frame %i\n", frames); 307 return false; 308 } 309 310 // go from the keyframe to the exact position 311 codec_context->hurry_up = 1; 312 do { 313 if(av_read_frame(format_context, &packet) < 0) 314 { 315 PRINTF(1)("Could not seek to frame %i\n", frames); 316 return false; 317 } 318 319 if(packet.stream_index == video_stream) 320 { 321 if(packet.pts >= frames-1) 322 break; 323 int frame_finished; 324 avcodec_decode_video(codec_context, frame, &frame_finished, packet.data, packet.size); 325 av_free_packet(&packet); 326 } 327 } while(1); 328 codec_context->hurry_up = 0; 329 330 this->frame_number = frames; 331 } 332 333 return true; 334 } 335 336 void MoviePlayer::start(float start_time) 337 { 338 //start_frame = start_time * fps; 339 start_frame = 0; 340 341 if(this->gotoFrame(start_frame)) 342 { 343 status = PLAY; 344 timer = 0; 345 346 this->gotoFrame(start_frame); 347 348 PRINTF(0)("start\n"); 349 } 50 350 } 51 351 52 352 void MoviePlayer::resume() 53 353 { 54 354 if(status == PAUSE) 355 { 356 status = PLAY; 357 PRINTF(0)("resume\n"); 358 } 55 359 } 56 360 57 361 void MoviePlayer::pause() 58 362 { 59 363 if(status == PLAY) 364 { 365 status = PAUSE; 366 PRINTF(0)("pause\n"); 367 } 60 368 } 61 369 62 370 void MoviePlayer::stop() 63 371 { 64 65 } 66 67 void MoviePlayer::tick(float time) 68 { 69 372 status = STOP; 373 374 PRINTF(0)("stop\n"); 375 } 376 377 void MoviePlayer::tick(float dt) 378 { 379 if(status == PLAY) 380 { 381 timer += dt; 382 actual_frame = timer * fps + start_frame; 383 if(actual_frame != frame_number) 384 { 385 if(actual_frame - frame_number == 1) 386 this->getNextFrame(); 387 else 388 this->skipFrame(actual_frame - frame_number - 1); 389 } 390 //PRINTF(0)("frame_number: %i\n", frame_number); 391 } 70 392 } 71 393 72 394 const void MoviePlayer::draw() 73 395 { 74 75 } 76 77 void MoviePlayer::setSpeed(float speed) 78 { 79 80 } 81 82 float MoviePlayer::getSpeed() 83 { 84 396 material->select(); 397 glBindTexture(GL_TEXTURE_2D, texture); 398 model->draw(); 399 400 LightManager::getInstance()->draw(); 401 } 402 403 void MoviePlayer::setFPS(float fps) 404 { 405 if(fps > 0) 406 this->fps = fps; 407 } 408 409 float MoviePlayer::getFPS() 410 { 411 return this->fps; 85 412 } 86 413 87 414 const MP_STATUS MoviePlayer::getStatus() 88 415 { 89 90 } 416 return this->status; 417 } 418 419 void MoviePlayer::printInformation() 420 { 421 if(!loading) 422 { 423 PRINTF(0)("Load first the media file with loadMovie\n"); 424 return; 425 } 426 427 PRINTF(0)("========================\n"); 428 PRINTF(0)("========================\n"); 429 PRINTF(0)("= MEDIACONTAINER =\n"); 430 PRINTF(0)("========================\n"); 431 PRINTF(0)("========================\n"); 432 PRINTF(0)("= AVFormatContext =\n"); 433 PRINTF(0)("========================\n"); 434 PRINTF(0)("filename: %s\n", format_context->filename); 435 PRINTF(0)("nb_streams: %i\n", format_context->nb_streams); 436 PRINTF(0)("duration: (%02d:%02d:%02d)\n", duration/3600, (duration%3600)/60, duration%60); 437 PRINTF(0)("file_size: %ikb\n", format_context->file_size/1024); 438 PRINTF(0)("bit_rate: %ikb/s\n", format_context->bit_rate/1000); 439 PRINTF(0)("nb_frames: %i\n", format_context->streams[video_stream]->nb_frames); 440 PRINTF(0)("r_frame_rate: %i\n", format_context->streams[video_stream]->r_frame_rate.num); 441 PRINTF(0)("fps: %0.2f\n", fps); 442 PRINTF(0)("========================\n"); 443 PRINTF(0)("= AVCodecContext =\n"); 444 PRINTF(0)("========================\n"); 445 PRINTF(0)("width: %i\n", codec_context->width); 446 PRINTF(0)("height: %i\n", codec_context->height); 447 PRINTF(0)("time_base.den: %i\n", codec_context->time_base.den); 448 PRINTF(0)("time_base.num: %i\n", codec_context->time_base.num); 449 PRINTF(0)("========================\n"); 450 PRINTF(0)("= AVCodec =\n"); 451 PRINTF(0)("========================\n"); 452 PRINTF(0)("codec name: %s\n", codec->name); 453 PRINTF(0)("========================\n"); 454 PRINTF(0)("========================\n"); 455 } -
branches/avi_play_merge/src/lib/graphics/importer/movie_player.h
r5960 r6486 8 8 #define _MOVIE_PLAYER 9 9 10 #include <SDL.h> 11 12 #ifdef HAVE_AVFORMAT_H 13 #include <avformat.h> 14 #else 15 #include <ffmpeg/avformat.h> 16 #endif 17 10 18 #include "glincl.h" 11 #include "sdlincl.h"12 19 13 /* include base_object.h since all classes are derived from this one */ 20 #include "light.h" 21 #include "texture.h" 22 #include "material.h" 23 #include "primitive_model.h" 24 25 // include base_object.h since all classes are derived from this one 14 26 #include "base_object.h" 15 27 16 /* using namespace std is default, this needs to be here */ 17 using namespace std; 18 19 /* The state of the MoviePlayer */ 28 // The state of the MoviePlayer 20 29 typedef enum MP_STATUS { 21 30 PLAY, 22 31 PAUSE, 23 STOP, 24 RECORD 32 STOP 25 33 }; 26 34 … … 30 38 private: 31 39 32 char* filename; 33 unsigned int width; 34 unsigned int height; 40 Model* model; 41 Material* material; 35 42 36 unsigned int frame_rate; 37 unsigned int current_frame; 38 float time_since_last_frame; 39 float speed; 40 41 SDL_Surface* screen; 43 AVFormatContext* format_context; 44 AVCodecContext* codec_context; 45 AVCodec* codec; 46 AVFrame* frame; 47 AVPacket packet; 48 AVFrame* RGB_frame; 49 50 GLuint texture; 51 uint8_t* data; 52 uint8_t* buffer; 53 int num_bytes; 54 int video_stream; 55 56 MP_STATUS status; 57 float timer; 58 int start_frame; 59 int actual_frame; 60 int frame_number; 61 float fps; 62 int duration; 63 bool loading; 42 64 43 65 public: 44 66 45 67 MoviePlayer(const char* filename); 68 MoviePlayer(); 46 69 ~MoviePlayer(); 47 70 48 void start(unsigned int start_frame); 71 bool loadMovie(const char* filename); 72 73 void start(float start_time); 49 74 void resume(); 50 75 void pause(); 51 76 void stop(); 52 77 53 void tick(float time);78 void tick(float dt); 54 79 const void draw(); 55 80 56 void set Speed(float speed);57 float get Speed();81 void setFPS(float fps); 82 float getFPS(); 58 83 const MP_STATUS getStatus(); 84 void printInformation(); 85 86 private: 87 88 void init(); 89 void getNextFrame(); 90 void skipFrame(int frames); 91 bool gotoFrame(int frames); 59 92 60 93 }; … … 62 95 63 96 64 #endif / * _MOVIE_PLAYER */97 #endif // _MOVIE_PLAYER -
branches/avi_play_merge/src/lib/graphics/importer/texture.cc
r6465 r6486 199 199 0xFF000000 200 200 #else 201 201 0xFF000000, 202 202 0x00FF0000, 203 203 0x0000FF00, -
branches/avi_play_merge/src/lib/graphics/importer/texture_sequence.cc
r5885 r6486 47 47 TextureSequence::~TextureSequence() 48 48 { 49 this->clearLists(); 50 } 51 52 void TextureSequence::clearLists() 53 { 49 54 // delete all images 50 55 while(!this->images.empty()) … … 54 59 } 55 60 56 this->setTexture(0);57 61 // delete all textures. 58 62 while(!this->textures.empty()) … … 63 67 } 64 68 } 65 66 69 67 70 /** … … 149 152 } 150 153 this->setAlpha(hasAlpha); 154 151 155 return true; 152 156 } 153 157 158 /** 159 * @brief adds a new Frame at the end of the Sequence. 160 * @param texture the texture to add at the end of the Sequence. 161 */ 162 bool TextureSequence::addFrame(GLuint texture) 163 { 164 if (texture == 0) 165 return false; 166 this->textures.push_back(texture); 154 167 168 return true; 169 } 155 170 156 171 /** … … 158 173 * @param frameNumber the n-th frame 159 174 */ 160 void TextureSequence::gotoFrame(unsigned int frameNumber)175 /*void TextureSequence::gotoFrame(unsigned int frameNumber) 161 176 { 162 177 if (this->textures.size() > frameNumber) 163 178 this->setTexture(this->textures[frameNumber]); 164 179 } 180 */ -
branches/avi_play_merge/src/lib/graphics/importer/texture_sequence.h
r5865 r6486 29 29 bool addFrame(const char* image); 30 30 bool addFrame(SDL_Surface* surface); 31 bool addFrame(GLuint texture); 32 33 void clearLists(); 31 34 32 35 virtual bool rebuild(); … … 35 38 inline unsigned int getFrameCount() const { return this->textures.size(); }; 36 39 37 void gotoFrame(unsigned int frameNumber);40 //void gotoFrame(unsigned int frameNumber); 38 41 /** @returns The textureID of the Frame @param frameNumber the n-th frame this texture-series. */ 39 42 inline GLuint getFrameTexture(unsigned int frameNumber) const { return (this->textures.size()>frameNumber)?this->textures[frameNumber]:0; }; -
branches/avi_play_merge/src/subprojects/importer/Makefile.am
r6310 r6486 7 7 8 8 bin_PROGRAMS = importer \ 9 multitex 9 multitex \ 10 movie_player_test 10 11 11 12 importer_LDADD = $(MAINSRCDIR)/lib/event/libORXevent.a \ … … 63 64 $(MAINSRCDIR)/lib/util/executor/executor.cc \ 64 65 $(MAINSRCDIR)/util/loading/factory.cc 66 67 movie_player_test_LDADD = $(MAINSRCDIR)/lib/event/libORXevent.a \ 68 $(MAINSRCDIR)/lib/parser/tinyxml/libtinyxml.a \ 69 $(MAINSRCDIR)/lib/graphics/libORXgraphics.a \ 70 $(MAINSRCDIR)/lib/shell/libORXshell.a \ 71 $(MAINSRCDIR)/lib/sound/libORXsound.a \ 72 $(MAINSRCDIR)/lib/graphics/importer/libORXimporter.a 73 74 movie_player_test_SOURCES= ../framework.cc \ 75 movie_player_test.cc \ 76 $(MAINSRCDIR)/util/state.cc \ 77 $(MAINSRCDIR)/world_entities/camera.cc \ 78 $(MAINSRCDIR)/lib/lang/base_object.cc \ 79 $(MAINSRCDIR)/lib/lang/class_list.cc \ 80 $(MAINSRCDIR)/lib/math/vector.cc \ 81 $(MAINSRCDIR)/util/loading/resource_manager.cc \ 82 $(MAINSRCDIR)/lib/parser/ini_parser/ini_parser.cc \ 83 $(MAINSRCDIR)/lib/coord/p_node.cc \ 84 $(MAINSRCDIR)/lib/coord/null_parent.cc \ 85 $(MAINSRCDIR)/util/loading/load_param.cc \ 86 $(MAINSRCDIR)/util/loading/load_param_description.cc \ 87 $(MAINSRCDIR)/lib/util/helper_functions.cc \ 88 $(MAINSRCDIR)/lib/util/substring.cc \ 89 $(MAINSRCDIR)/lib/util/color.cc \ 90 $(MAINSRCDIR)/lib/util/multi_type.cc \ 91 $(MAINSRCDIR)/lib/util/executor/executor.cc \ 92 $(MAINSRCDIR)/util/loading/factory.cc -
branches/avi_play_merge/src/subprojects/importer/multitex.cc
r5866 r6486 10 10 11 11 ### File Specific: 12 main-programmer: Benjamin Grauer12 main-programmer: David Hasenfratz 13 13 co-programmer: ... 14 14 … … 20 20 #include "light.h" 21 21 22 #include "texture_sequence.h"23 22 #include "material.h" 24 25 #include "objModel.h"26 27 23 #include "primitive_model.h" 28 24 #include <stdlib.h> 29 25 30 #include " resource_manager.h"26 #include "media_container.h" 31 27 32 28 Model* obj; 33 TextureSequence* seq;34 Texture* test;35 29 Material* testMat; 30 MediaContainer* media_container; 36 31 37 float counter = 0; 32 int counter = 0; 33 float timer = 0; 34 float fps; 38 35 39 36 40 37 void Framework::moduleInit(int argc, char** argv) 41 38 { 42 ResourceManager::getInstance()->addImageDir("./"); 39 if( argc <= 1) 40 { 41 printf("Wrong arguments try following notations:\n"); 42 printf("./multitex [media_file]\n"); 43 exit(0); 44 } 45 46 media_container = new MediaContainer(argv[1]); 43 47 44 48 testMat = new Material; 45 46 seq = new TextureSequence(); 47 for (int i = 1; i < argc; i++) 48 { 49 seq->addFrame(argv[i]); 50 printf("%s\n", argv[i]); 51 } 52 test = new Texture(argv[1]); 53 testMat->setDiffuseMap(argv[1]); 54 55 ResourceManager::getInstance()->addImageDir(""); 56 57 58 obj = new PrimitiveModel(PRIM_SPHERE, 10.0); 59 60 ResourceManager::getInstance()->debug(); 49 testMat->setDiffuseMap("maps/radialTransparency.png"); 50 obj = new PrimitiveModel(PRIM_PLANE, 10.0); 61 51 62 52 LightManager* lightMan = LightManager::getInstance(); … … 64 54 (new Light())->setAbsCoor(5.0, 10.0, 40.0); 65 55 (new Light())->setAbsCoor(-10, -20, -100); 56 57 fps = media_container->getFPS(); 66 58 } 67 59 … … 73 65 switch (event->key.keysym.sym) 74 66 { 75 case SDLK_i: 67 case SDLK_1: 68 obj = new PrimitiveModel(PRIM_CUBE, 10.0); 69 break; 70 case SDLK_2: 71 obj = new PrimitiveModel(PRIM_SPHERE, 10.0); 72 break; 73 case SDLK_3: 74 obj = new PrimitiveModel(PRIM_PLANE, 10.0); 75 break; 76 // increase fps 77 case SDLK_9: 78 fps++; 79 PRINTF(0)("fps: %0.2f\n", fps); 80 break; 81 // decrease fps 82 case SDLK_8: 83 if(fps > 0) 84 fps--; 85 PRINTF(0)("fps: %0.2f\n", fps); 76 86 break; 77 87 } … … 81 91 void Framework::moduleTick(float dt) 82 92 { 83 counter+=dt;93 timer += dt; 84 94 85 seq->gotoFrame((unsigned int)counter); 86 if ((unsigned int)counter > seq->getFrameCount()) 87 counter = 0; 95 if(counter != fps * timer) 96 { 97 counter = fps * timer; 98 99 if (counter >= media_container->getFrameCount()) 100 { 101 timer = 0; 102 counter = 0; 103 } 104 } 88 105 } 89 106 … … 91 108 { 92 109 testMat->select(); 93 glBindTexture(GL_TEXTURE_2D, seq->getTexture());110 glBindTexture(GL_TEXTURE_2D, media_container->getFrameTexture(counter)); 94 111 obj->draw(); 95 112 … … 97 114 } 98 115 99 100 116 void Framework::moduleHelp(void) const 101 117 {
Note: See TracChangeset
for help on using the changeset viewer.