Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6324 in orxonox.OLD for branches/avi_play/src/lib/graphics


Ignore:
Timestamp:
Dec 27, 2005, 10:25:48 PM (19 years ago)
Author:
hdavid
Message:

branches\avi_play: MoviePlayer works, at the moment not very fast

Location:
branches/avi_play/src/lib/graphics/importer
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/avi_play/src/lib/graphics/importer/media_container.cc

    r6323 r6324  
    8787}
    8888
    89 GLuint MediaContainer::getFrame(int frame_number)
     89void MediaContainer::gotoFrame(int frame_number)
    9090{
    9191  // seek doesnt work for the first two frames
     
    9696    av_seek_frame(format_context, video_stream, 0, AVSEEK_FLAG_BACKWARD);
    9797    frame_num = 0;
    98     return this->getNextFrame();
    9998  }
    10099  else
     
    117116 
    118117    frame_num = frame_number;
    119 
    120     return this->getNextFrame();
    121118  }
    122119}
     
    215212}
    216213
    217 void MediaContainer::skipFrame(int num_frames)
    218 {
    219 
     214GLuint MediaContainer::skipFrame(int num_frames)
     215{
     216  frame_num += num_frames;
     217 
     218  while(num_frames != 0)
     219  {
     220    if(av_read_frame(format_context, &packet) < 0)
     221      break;
     222    if(packet.stream_index == video_stream)
     223    {
     224      int frame_finished;
     225      // We have to decode the frame to not get ugly fragments
     226      avcodec_decode_video(codec_context, frame, &frame_finished,
     227                            packet.data, packet.size);
     228       
     229      // Did we get a video frame?
     230      if(frame_finished)
     231        num_frames--;
     232    }
     233    av_free_packet(&packet);
     234  }
     235 
     236  return this->getNextFrame();
    220237}
    221238
  • branches/avi_play/src/lib/graphics/importer/media_container.h

    r6320 r6324  
    5858
    5959  void init();
    60   GLuint getFrame(int frame_number);
     60  void gotoFrame(int frame_number);
    6161  GLuint getNextFrame();
    62   void skipFrame(int num_frames);
     62  GLuint skipFrame(int num_frames);
    6363  vector<GLuint> getFrameList();
    6464  void loadMedia(const char* filename);
  • branches/avi_play/src/lib/graphics/importer/movie_player.cc

    r6323 r6324  
    5757{
    5858  status = STOP;
     59  timer = 0;
    5960
    6061  material = new Material;
     
    8283void MoviePlayer::start(unsigned int start_frame)
    8384{
    84   texture = media_container->getFrame(start_frame);
     85  status = PLAY;
     86  timer = 0;
     87  fps = media_container->getFPS();
    8588
    86   status = PLAY;
     89  media_container->gotoFrame(start_frame);
     90
     91   PRINTF(0)("start\n");
    8792}
    8893
     
    9095{
    9196  if(status == STOP)
    92     texture = media_container->getFrame(0);
    93   status = PLAY;
     97    this->start(0);
     98  else
     99    status = PLAY;
     100
     101   PRINTF(0)("resume\n");
    94102}
    95103
     
    98106  if(status != STOP)
    99107    status = PAUSE;
     108
     109  PRINTF(0)("pause\n");
    100110}
    101111
     
    104114  status = STOP;
    105115  texture = NULL;
     116
     117  PRINTF(0)("stop\n");
    106118}
    107119
    108 void MoviePlayer::tick(float time)
     120void MoviePlayer::tick(float dt)
    109121{
    110122  if(status == PLAY)
    111123  {
    112     texture = media_container->getNextFrame();
     124    current_frame = media_container->getFrameNumber();
     125    timer += dt;
     126    actuel_frame = timer * fps;
     127
     128    if(actuel_frame != current_frame)
     129    {
     130      if(actuel_frame - current_frame == 1)
     131        texture = media_container->getNextFrame();
     132      else
     133        texture = media_container->skipFrame(actuel_frame - current_frame - 1);
     134    }   
    113135    //PRINTF(0)("frame_number: %i\n", media_container->getFrameNumber());
    114     if(texture == NULL)
    115       status = STOP;
     136
     137    if(texture == NULL && current_frame != 0)
     138      this->stop();
    116139  }
    117140}
  • branches/avi_play/src/lib/graphics/importer/movie_player.h

    r6317 r6324  
    3939
    4040  MP_STATUS status;     
    41   float speed; 
     41  float speed;
     42  float timer;
     43  int actuel_frame;
     44  int current_frame;
     45  float fps; 
    4246
    4347public:
     
    5559        void stop();
    5660
    57         void tick(float time);
     61        void tick(float dt);
    5862        const void draw();
    5963
Note: See TracChangeset for help on using the changeset viewer.