1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright (c) 1992-2001 by Sun Microsystems, Inc. 24*0Sstevel@tonic-gate * All rights reserved. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #ifndef _MULTIMEDIA_AUDIOFILE_H 28*0Sstevel@tonic-gate #define _MULTIMEDIA_AUDIOFILE_H 29*0Sstevel@tonic-gate 30*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 31*0Sstevel@tonic-gate 32*0Sstevel@tonic-gate #ifdef NO_EXTERN_C 33*0Sstevel@tonic-gate 34*0Sstevel@tonic-gate #ifdef __cplusplus 35*0Sstevel@tonic-gate extern "C" { 36*0Sstevel@tonic-gate #endif 37*0Sstevel@tonic-gate 38*0Sstevel@tonic-gate #endif /* NO_EXTERN_C */ 39*0Sstevel@tonic-gate 40*0Sstevel@tonic-gate #include <AudioUnixfile.h> 41*0Sstevel@tonic-gate #include <sys/types.h> 42*0Sstevel@tonic-gate #include <sys/mman.h> 43*0Sstevel@tonic-gate 44*0Sstevel@tonic-gate // A 'primitive type' for memory mapped file access types 45*0Sstevel@tonic-gate enum vmaccess_t { 46*0Sstevel@tonic-gate NormalAccess = 0, RandomAccess = 1, SequentialAccess = 2 47*0Sstevel@tonic-gate }; 48*0Sstevel@tonic-gate 49*0Sstevel@tonic-gate class VMAccess { 50*0Sstevel@tonic-gate private: 51*0Sstevel@tonic-gate vmaccess_t type; // combined mode 52*0Sstevel@tonic-gate public: 53*0Sstevel@tonic-gate VMAccess(vmaccess_t x = NormalAccess): type(x) { } // Constructor 54*0Sstevel@tonic-gate inline operator vmaccess_t() // Cast to enum 55*0Sstevel@tonic-gate { return (type); } 56*0Sstevel@tonic-gate inline operator int() { // Cast to integer 57*0Sstevel@tonic-gate switch (type) { 58*0Sstevel@tonic-gate case NormalAccess: return (MADV_NORMAL); 59*0Sstevel@tonic-gate case RandomAccess: return (MADV_RANDOM); 60*0Sstevel@tonic-gate case SequentialAccess: return (MADV_SEQUENTIAL); 61*0Sstevel@tonic-gate } 62*0Sstevel@tonic-gate } 63*0Sstevel@tonic-gate }; 64*0Sstevel@tonic-gate 65*0Sstevel@tonic-gate 66*0Sstevel@tonic-gate // This is the 'base' class for regular files containing audio data 67*0Sstevel@tonic-gate class AudioFile : public AudioUnixfile { 68*0Sstevel@tonic-gate private: 69*0Sstevel@tonic-gate static const FileAccess defmode; // Default access mode 70*0Sstevel@tonic-gate static const char *AUDIO_PATH; // Default path env name 71*0Sstevel@tonic-gate 72*0Sstevel@tonic-gate off_t hdrsize; // length of file header 73*0Sstevel@tonic-gate off_t seekpos; // current system file pointer 74*0Sstevel@tonic-gate Double origlen; // initial length of file 75*0Sstevel@tonic-gate 76*0Sstevel@tonic-gate caddr_t mapaddr; // for mmaping RO files 77*0Sstevel@tonic-gate off_t maplen; // length of mmaped region 78*0Sstevel@tonic-gate VMAccess vmaccess; // vm (mmap) access type 79*0Sstevel@tonic-gate 80*0Sstevel@tonic-gate AudioFile operator=(AudioFile); // Assignment is illegal 81*0Sstevel@tonic-gate 82*0Sstevel@tonic-gate protected: 83*0Sstevel@tonic-gate // Open named file 84*0Sstevel@tonic-gate virtual AudioError tryopen( 85*0Sstevel@tonic-gate const char *, int); 86*0Sstevel@tonic-gate // Create named file 87*0Sstevel@tonic-gate virtual AudioError createfile( 88*0Sstevel@tonic-gate const char *path); // filename 89*0Sstevel@tonic-gate 90*0Sstevel@tonic-gate // class AudioUnixfile methods specialized here 91*0Sstevel@tonic-gate // Seek in input stream 92*0Sstevel@tonic-gate virtual AudioError seekread( 93*0Sstevel@tonic-gate Double pos, // position to seek to 94*0Sstevel@tonic-gate off_t& offset); // returned byte offset 95*0Sstevel@tonic-gate // Seek in output stream 96*0Sstevel@tonic-gate virtual AudioError seekwrite( 97*0Sstevel@tonic-gate Double pos, // position to seek to 98*0Sstevel@tonic-gate off_t& offset); // returned byte offset 99*0Sstevel@tonic-gate 100*0Sstevel@tonic-gate public: 101*0Sstevel@tonic-gate AudioFile(); // Constructor w/no args 102*0Sstevel@tonic-gate 103*0Sstevel@tonic-gate // Constructor with path 104*0Sstevel@tonic-gate AudioFile( 105*0Sstevel@tonic-gate const char *path, // filename 106*0Sstevel@tonic-gate const FileAccess acc = defmode); // access mode 107*0Sstevel@tonic-gate virtual ~AudioFile(); // Destructor 108*0Sstevel@tonic-gate 109*0Sstevel@tonic-gate // Set tmpfile location 110*0Sstevel@tonic-gate static AudioError SetTempPath( 111*0Sstevel@tonic-gate const char *path); // directory path 112*0Sstevel@tonic-gate 113*0Sstevel@tonic-gate // class AudioUnixfile methods specialized here 114*0Sstevel@tonic-gate virtual void SetBlocking(Boolean) { } // No-op for files 115*0Sstevel@tonic-gate 116*0Sstevel@tonic-gate // front end to madvise 117*0Sstevel@tonic-gate AudioError SetAccessType( 118*0Sstevel@tonic-gate VMAccess vmacc); // (normal, random, seq access) 119*0Sstevel@tonic-gate 120*0Sstevel@tonic-gate inline VMAccess GetAccessType() const { // get vm access type 121*0Sstevel@tonic-gate return (vmaccess); 122*0Sstevel@tonic-gate } 123*0Sstevel@tonic-gate 124*0Sstevel@tonic-gate virtual AudioError Create(); // Create file 125*0Sstevel@tonic-gate virtual AudioError Open(); // Open file 126*0Sstevel@tonic-gate 127*0Sstevel@tonic-gate // ... with search path 128*0Sstevel@tonic-gate virtual AudioError OpenPath( 129*0Sstevel@tonic-gate const char *path = AUDIO_PATH); 130*0Sstevel@tonic-gate virtual AudioError Close(); // Close file 131*0Sstevel@tonic-gate 132*0Sstevel@tonic-gate // Read from position 133*0Sstevel@tonic-gate virtual AudioError ReadData( 134*0Sstevel@tonic-gate void* buf, // buffer to fill 135*0Sstevel@tonic-gate size_t& len, // buffer length (updated) 136*0Sstevel@tonic-gate Double& pos); // start position (updated) 137*0Sstevel@tonic-gate 138*0Sstevel@tonic-gate // Write at position 139*0Sstevel@tonic-gate virtual AudioError WriteData( 140*0Sstevel@tonic-gate void* buf, // buffer to copy 141*0Sstevel@tonic-gate size_t& len, // buffer length (updated) 142*0Sstevel@tonic-gate Double& pos); // start position (updated) 143*0Sstevel@tonic-gate 144*0Sstevel@tonic-gate // copy to another audio obj. 145*0Sstevel@tonic-gate virtual AudioError AsyncCopy( 146*0Sstevel@tonic-gate Audio* ap, // dest audio object 147*0Sstevel@tonic-gate Double& frompos, 148*0Sstevel@tonic-gate Double& topos, 149*0Sstevel@tonic-gate Double& limit); 150*0Sstevel@tonic-gate 151*0Sstevel@tonic-gate // class Audio methods specialized here 152*0Sstevel@tonic-gate virtual Boolean isFile() const { return (TRUE); } 153*0Sstevel@tonic-gate }; 154*0Sstevel@tonic-gate 155*0Sstevel@tonic-gate #ifdef NO_EXTERN_C 156*0Sstevel@tonic-gate 157*0Sstevel@tonic-gate #ifdef __cplusplus 158*0Sstevel@tonic-gate } 159*0Sstevel@tonic-gate #endif 160*0Sstevel@tonic-gate 161*0Sstevel@tonic-gate #endif /* NO_EXTERN_C */ 162*0Sstevel@tonic-gate 163*0Sstevel@tonic-gate #endif /* !_MULTIMEDIA_AUDIOFILE_H */ 164