vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / media / plugins / asf_reader / ASFFileReader.h
blob1bd94f889284c3236c25f2b2b0c79adb686b5b38
1 /*
2 * Copyright (c) 2005, David McPaul
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
18 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
22 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
23 * OF THE POSSIBILITY OF SUCH DAMAGE.
25 #ifndef _ASF_FILE_READER_H
26 #define _ASF_FILE_READER_H
28 #include <File.h>
29 #include <MediaDefs.h>
30 #include <MediaFormats.h>
31 #include <SupportDefs.h>
33 #include <vector>
35 extern "C" {
36 #include "libasf/asf.h"
38 #include "ASFIndex.h"
40 struct ASFAudioFormat {
41 uint16 Compression;
42 uint16 NoChannels;
43 uint32 SamplesPerSec;
44 uint32 AvgBytesPerSec;
45 uint16 BlockAlign;
46 uint16 BitsPerSample;
47 uint32 extraDataSize;
48 uint8 *extraData;
51 struct ASFVideoFormat {
52 uint32 Compression;
53 uint32 VideoWidth;
54 uint32 VideoHeight;
55 uint16 Planes;
56 uint16 BitCount;
57 uint32 FrameRate;
58 uint32 FrameScale;
59 uint32 FrameCount;
60 uint32 extraDataSize;
61 uint8 *extraData;
64 // ASF file reader
65 class ASFFileReader {
66 private:
67 off_t StreamSize;
68 BPositionIO *theStream;
69 asf_file_t *asfFile;
70 asf_packet_t *packet;
71 std::vector<StreamEntry> streams;
73 void ParseIndex();
75 public:
76 ASFFileReader(BPositionIO *pStream);
77 virtual ~ASFFileReader();
79 status_t ParseFile();
81 bool IsEndOfFile(off_t pPosition);
82 bool IsEndOfFile();
83 bool IsEndOfData(off_t pPosition);
85 // Is this a asf file
86 static bool IsSupported(BPositionIO *source);
88 // How many tracks in file
89 uint32 getStreamCount();
91 // the Stream duration indexed by streamIndex
92 bigtime_t getStreamDuration(uint32 streamIndex);
94 bool getAudioFormat(uint32 streamIndex, ASFAudioFormat *format);
95 bool getVideoFormat(uint32 streamIndex, ASFVideoFormat *format);
97 // The no of frames in the Stream indexed by streamIndex
98 uint32 getFrameCount(uint32 streamIndex);
100 // Is stream (track) a video track
101 bool IsVideo(uint32 streamIndex);
102 // Is stream (track) a audio track
103 bool IsAudio(uint32 streamIndex);
105 BPositionIO *Source() {return theStream;};
107 IndexEntry GetIndex(uint32 streamIndex, uint32 frameNo);
108 bool HasIndex(uint32 streamIndex, uint32 frameNo);
110 uint32 GetFrameForTime(uint32 streamIndex, bigtime_t time);
112 bool GetNextChunkInfo(uint32 streamIndex, uint32 pFrameNo, char **buffer, uint32 *size, bool *keyframe, bigtime_t *pts);
114 static int32_t read(void *opaque, void *buffer, int32_t size);
115 static int32_t write(void *opaque, void *buffer, int32_t size);
116 static int64_t seek(void *opaque, int64_t offset);
119 #endif