Subversion Repositories Games.Descent

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.     SMPEG - SDL MPEG Player Library
  3.     Copyright (C) 1999  Loki Entertainment Software
  4.  
  5.     This library is free software; you can redistribute it and/or
  6.     modify it under the terms of the GNU Library General Public
  7.     License as published by the Free Software Foundation; either
  8.     version 2 of the License, or (at your option) any later version.
  9.  
  10.     This library is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.     Library General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU Library General Public
  16.     License along with this library; if not, write to the Free
  17.     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. /* The generic MPEG stream class */
  21.  
  22. #ifndef _MPEGSTREAM_H_
  23. #define _MPEGSTREAM_H_
  24.  
  25. #include "SDL_types.h"
  26. #include "MPEGerror.h"
  27. #include "MPEGvideo.h"
  28. #include "MPEGaudio.h"
  29. #include "MPEGlist.h"
  30.  
  31. #define AUDIO_STREAMID  0xc0
  32. #define VIDEO_STREAMID  0xe0
  33. #define SYSTEM_STREAMID 0xbb
  34.  
  35. struct MPEGstream_marker
  36. {
  37.     /* Data to mark part of the stream */
  38.     MPEGlist * marked_buffer;
  39.     Uint8 *marked_data;
  40.     Uint8 *marked_stop;  
  41. };
  42.  
  43. class MPEGstream
  44. {
  45. public:
  46.     MPEGstream(class MPEGsystem * System, Uint8 Streamid);
  47.     ~MPEGstream();
  48.  
  49.     /* Cleanup the buffers and reset the stream */
  50.     void reset_stream(void);
  51.  
  52.     /* Rewind the stream */
  53.     void rewind_stream(void);
  54.  
  55.     /* Go to the next packet in the stream */
  56.     bool next_packet(bool recurse = true, bool update_timestamp = true);
  57.  
  58.     /* Mark a position in the data stream */
  59.     MPEGstream_marker *new_marker(int offset);
  60.  
  61.     /* Jump to the marked position */
  62.     bool seek_marker(MPEGstream_marker const * marker);
  63.  
  64.     /* Jump to last successfully marked position */
  65.     void delete_marker(MPEGstream_marker * marker);
  66.  
  67.     /* Copy data from the stream to a local buffer */
  68.     Uint32 copy_data(Uint8 *area, Sint32 size, bool short_read = false);
  69.  
  70.     /* Copy a byte from the stream */
  71.     int copy_byte(void);
  72.  
  73.     /* Check for end of file or an error in the stream */
  74.     bool eof(void) const;
  75.  
  76.     /* Insert a new packet at the end of the stream */
  77.     void insert_packet(Uint8 * data, Uint32 size, double timestamp=-1);
  78.  
  79.     /* Check for unused buffers and free them */
  80.     void garbage_collect(void);
  81.  
  82.     /* Enable or disable the stream */
  83.     void enable(bool toggle);
  84.  
  85.     /* Get stream time */
  86.     double time();
  87.  
  88.     Uint32 pos;
  89.  
  90.     Uint8 streamid;
  91.  
  92. protected:
  93.     Uint8 *data;
  94.     Uint8 *stop;
  95.  
  96.     Uint32 preread_size;
  97.  
  98.     class MPEGsystem * system;
  99.     MPEGlist * br;
  100.     bool cleareof;
  101.     bool enabled;
  102.  
  103.     SDL_mutex * mutex;
  104.  
  105.     /* Get a buffer from the stream */
  106.     bool next_system_buffer(void);
  107.  
  108. public:
  109.     /* "pos" where "timestamp" belongs */
  110.     Uint32 timestamp_pos;
  111.     double timestamp;
  112. };
  113.  
  114. #endif /* _MPEGSTREAM_H_ */
  115.  
  116.  
  117.