Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6317 in orxonox.OLD for branches/avi_play


Ignore:
Timestamp:
Dec 27, 2005, 2:24:13 PM (19 years ago)
Author:
hdavid
Message:

branches\avi_play: MediaContainer returns a texture not a surface, it's faster. MoviePlayer can display the textures, playspeed not yet implemented

Location:
branches/avi_play/src
Files:
7 edited

Legend:

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

    r6290 r6317  
    5050MediaContainer::~MediaContainer()
    5151{
    52   // delete all surfaces in the list
    53   while(!this->surface_list.empty())
     52  // delete all textures.
     53  while(!this->texture_list.empty())
    5454  {
    55     SDL_FreeSurface(this->surface_list.back());
    56     this->surface_list.pop_back();
     55    if (glIsTexture(this->texture_list.back()))
     56      glDeleteTextures(1, &this->texture_list.back());
     57    this->texture_list.pop_back();
    5758  }
     59  glDeleteTextures(1, &texture);
    5860  SDL_FreeSurface(surface);
    5961
     
    8284
    8385  fps = 0;
    84 }
    85 
    86 SDL_Surface* MediaContainer::getFrame(int frame_number)
     86  frame_num = 0;
     87}
     88
     89GLuint MediaContainer::getFrame(int frame_number)
    8790{
    8891  // seek doesnt work for the first two frames
     
    112115}
    113116
    114 SDL_Surface* MediaContainer::getNextFrame()
     117GLuint MediaContainer::getNextFrame()
    115118{
    116119  /* get next frame */
     
    127130                           packet.data, packet.size);
    128131
     132      // Free the packet that was allocated by av_read_frame
     133      av_free_packet(&packet);
     134     
    129135      // Did we get a video frame?
    130136      if(frame_finished)
    131137      {
     138        frame_num++;
    132139        //PRINTF(1)("frame_number: %i\n", this->getFrameNumber());
    133140        // Conversion from YUV to RGB
     
    163170                                            );
    164171
    165         return surface;
     172        // NOTE: use glTexSubImage2D, it's faster!! //
     173        /* Create an OpenGL texture from the surface */
     174        glGenTextures(1, &texture);
     175        glBindTexture(GL_TEXTURE_2D, texture);
     176        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
     177        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
     178        // build the Texture
     179        glTexImage2D(GL_TEXTURE_2D,
     180                    0,
     181                    GL_RGB,
     182                    surface->w, surface->h,
     183                    0,
     184                    GL_RGB,
     185                    GL_UNSIGNED_BYTE,
     186                    surface->pixels);
     187        // build the MipMaps
     188        gluBuild2DMipmaps(GL_TEXTURE_2D,
     189                          GL_RGB,
     190                          surface->w,
     191                          surface->h,
     192                          GL_RGB,
     193                          GL_UNSIGNED_BYTE,
     194                          surface->pixels);
     195        glBindTexture(GL_TEXTURE_2D, 0);
     196
     197        return texture;
    166198      }
    167199    }
    168     // Free the packet that was allocated by av_read_frame
    169     av_free_packet(&packet);
     200    else
     201    {
     202      av_free_packet(&packet);
     203      this->getNextFrame();
     204    }
    170205  }
    171206  else
     
    173208}
    174209
    175 vector<SDL_Surface*> MediaContainer::getFrameList()
    176 {
    177 
    178   while((surface = this->getNextFrame()) != NULL)
    179     surface_list.push_back(surface);
    180 
    181   return surface_list;
     210vector<GLuint> MediaContainer::getFrameList()
     211{
     212
     213  while((texture = this->getNextFrame()) != NULL)
     214    texture_list.push_back(texture);
     215
     216  return texture_list;
    182217}
    183218
     
    189224
    190225  // Open file
    191   sprintf(filename, "frame%i.ppm", codec_context->frame_number);
     226  sprintf(filename, "frame%i.ppm", frame_num);
    192227  file = fopen(filename, "wb");
    193228  if(file == NULL)
     
    264299  // duration
    265300  duration = format_context->duration / 1000000LL;
     301
     302  frame_num = 0;
    266303}
    267304
     
    278315int MediaContainer::getFrameNumber()
    279316{
    280   return codec_context->frame_number;
     317  return frame_num;
    281318}
    282319
  • branches/avi_play/src/lib/graphics/importer/media_container.h

    r6290 r6317  
    2020#include "base_object.h"
    2121
     22#include "glincl.h"
     23
    2224/* using namespace std is default, this needs to be here */
    2325using namespace std;
     
    3032  double fps;
    3133  SDL_Surface* surface;
     34  GLuint texture;
    3235  uint8_t* data;
    3336
     
    4447  int video_stream;
    4548  int duration;
     49  int frame_num;
    4650
    47   vector<SDL_Surface*>    surface_list;
     51  vector<GLuint>    texture_list;
    4852
    4953public:
     
    5458
    5559  void init();
    56   SDL_Surface* getFrame(int frame_number);
    57   SDL_Surface* getNextFrame();
    58   vector<SDL_Surface*> getFrameList();
     60  GLuint getFrame(int frame_number);
     61  GLuint getNextFrame();
     62  vector<GLuint> getFrameList();
    5963  void loadMedia(const char* filename);
    6064
  • branches/avi_play/src/lib/graphics/importer/movie_player.cc

    r6290 r6317  
    5858  status = STOP;
    5959
    60   tex = new Texture();
     60  //tex = new Texture();
    6161  material = new Material;
    6262
     
    103103void MoviePlayer::tick(float time)
    104104{
    105   surface = media_container->getNextFrame();
    106 
    107   if(surface == NULL)
    108     texture = NULL;
    109   else
    110   {
    111     bool hasAlpha;
    112     SDL_Surface* newSurf = tex->prepareSurface(surface, hasAlpha);
    113     if (newSurf != NULL)
    114       texture = Texture::loadTexToGL(newSurf);
    115     else
    116       texture = NULL;
    117   }
     105  texture = media_container->getNextFrame();
    118106}
    119107
  • branches/avi_play/src/lib/graphics/importer/movie_player.h

    r6290 r6317  
    99
    1010#include "glincl.h"
    11 #include "sdlincl.h"
     11//#include "sdlincl.h"
    1212
    1313#include "media_container.h"
     
    1919/* include base_object.h since all classes are derived from this one */
    2020#include "base_object.h"
    21 
    22 /* using namespace std is default, this needs to be here */
    23 using namespace std;
    24 
    25 class MediaContainer;
    26 class Model;
    27 class Material;
    28 class Texture;
    2921
    3022/* The state of the MoviePlayer */
     
    4335  Model* model;
    4436  Material* material;
    45   Texture* tex;
    4637
    47   SDL_Surface* surface;
    4838  GLuint texture;
    4939
  • branches/avi_play/src/lib/graphics/importer/texture_sequence.cc

    r6163 r6317  
    153153}
    154154
    155 bool TextureSequence::addFrameList(std::vector<SDL_Surface*> surfaces)
     155bool TextureSequence::addFrameList(std::vector<GLuint> textures)
    156156{
    157   // add the surfaces to the list
    158   for(int i = 0; i < surfaces.size(); i++)
    159     this->addFrame(surfaces[i]);
     157  // add the textures to the list
     158  for(int i = 0; i < textures.size(); i++)
     159    this->addFrame(textures[i]);
    160160}
    161161
  • branches/avi_play/src/lib/graphics/importer/texture_sequence.h

    r6163 r6317  
    3030    bool addFrame(SDL_Surface* surface);
    3131    bool addFrame(GLuint texture);
    32     bool addFrameList(std::vector<SDL_Surface*> surfaces);
     32    bool addFrameList(std::vector<GLuint> textures);
    3333
    3434    virtual bool rebuild();
  • branches/avi_play/src/subprojects/importer/movie_player_test.cc

    r6290 r6317  
    3636
    3737void Framework::moduleTick(float dt)
    38 {
     38{ 
    3939  movie_player->tick(dt);
    4040}
Note: See TracChangeset for help on using the changeset viewer.