File: MPEGstream.h

package info (click to toggle)
smpeg 0.4.5%2Bcvs20030824-8
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,240 kB
  • sloc: cpp: 14,970; sh: 8,042; ansic: 2,316; asm: 544; makefile: 122
file content (116 lines) | stat: -rw-r--r-- 2,956 bytes parent folder | download | duplicates (16)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
    SMPEG - SDL MPEG Player Library
    Copyright (C) 1999  Loki Entertainment Software

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public
    License along with this library; if not, write to the Free
    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

/* The generic MPEG stream class */

#ifndef _MPEGSTREAM_H_
#define _MPEGSTREAM_H_

#include "SDL_types.h"
#include "MPEGerror.h"
#include "MPEGvideo.h"
#include "MPEGaudio.h"
#include "MPEGlist.h"

#define AUDIO_STREAMID  0xc0
#define VIDEO_STREAMID  0xe0
#define SYSTEM_STREAMID 0xbb

struct MPEGstream_marker
{
    /* Data to mark part of the stream */
    MPEGlist * marked_buffer;
    Uint8 *marked_data;
    Uint8 *marked_stop;  
};

class MPEGstream
{
public:
    MPEGstream(class MPEGsystem * System, Uint8 Streamid);
    ~MPEGstream();

    /* Cleanup the buffers and reset the stream */
    void reset_stream(void);

    /* Rewind the stream */
    void rewind_stream(void);

    /* Go to the next packet in the stream */
    bool next_packet(bool recurse = true, bool update_timestamp = true);
 
    /* Mark a position in the data stream */
    MPEGstream_marker *new_marker(int offset);

    /* Jump to the marked position */
    bool seek_marker(MPEGstream_marker const * marker);

    /* Jump to last successfully marked position */
    void delete_marker(MPEGstream_marker * marker);

    /* Copy data from the stream to a local buffer */
    Uint32 copy_data(Uint8 *area, Sint32 size, bool short_read = false);

    /* Copy a byte from the stream */
    int copy_byte(void);

    /* Check for end of file or an error in the stream */
    bool eof(void) const;

    /* Insert a new packet at the end of the stream */
    void insert_packet(Uint8 * data, Uint32 size, double timestamp=-1);

    /* Check for unused buffers and free them */
    void garbage_collect(void);

    /* Enable or disable the stream */
    void enable(bool toggle);

    /* Get stream time */
    double time();

    Uint32 pos;

    Uint8 streamid;

protected:
    Uint8 *data;
    Uint8 *stop;

    Uint32 preread_size;

    class MPEGsystem * system;
    MPEGlist * br;
    bool cleareof;
    bool enabled;

    SDL_mutex * mutex;

    /* Get a buffer from the stream */
    bool next_system_buffer(void);

public:
    /* "pos" where "timestamp" belongs */
    Uint32 timestamp_pos;
    double timestamp;
};

#endif /* _MPEGSTREAM_H_ */