liveMedia/include/InputFile.hh File Reference

#include <UsageEnvironment.hh>
#include <stdio.h>
#include <sys/stat.h>

Include dependency graph for InputFile.hh:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

FILE * OpenInputFile (UsageEnvironment &env, char const *fileName)
void CloseInputFile (FILE *fid)
u_int64_t GetFileSize (char const *fileName, FILE *fid)
int64_t SeekFile64 (FILE *fid, int64_t offset, int whence)
int64_t TellFile64 (FILE *fid)
Boolean FileIsSeekable (FILE *fid)


Function Documentation

void CloseInputFile ( FILE *  fid  ) 

Definition at line 43 of file InputFile.cpp.

References NULL.

Referenced by MPEG2TransportStreamIndexFile::closeFid(), AMRAudioFileSource::createNew(), ADTSAudioFileSource::createNew(), ADTSAudioFileSource::~ADTSAudioFileSource(), AMRAudioFileSource::~AMRAudioFileSource(), ByteStreamFileSource::~ByteStreamFileSource(), MP3StreamState::~MP3StreamState(), and WAVAudioFileSource::~WAVAudioFileSource().

00043                                {
00044   // Don't close 'stdin', in case we want to use it again later.
00045   if (fid != NULL && fid != stdin) fclose(fid);
00046 }

Boolean FileIsSeekable ( FILE *  fid  ) 

Definition at line 105 of file InputFile.cpp.

References False, SeekFile64(), and True.

Referenced by ByteStreamFileSource::ByteStreamFileSource(), and WAVAudioFileSource::WAVAudioFileSource().

00105                                   {
00106   if (SeekFile64(fid, 1, SEEK_CUR) < 0) {
00107     return False;
00108   }
00109 
00110   SeekFile64(fid, -1, SEEK_CUR); // seek back to where we were
00111   return True;
00112 }

u_int64_t GetFileSize ( char const *  fileName,
FILE *  fid 
)

Definition at line 48 of file InputFile.cpp.

References NULL, SeekFile64(), and TellFile64().

Referenced by WAVAudioFileSource::createNew(), MP3FileSource::createNew(), ByteStreamFileSource::createNew(), and MPEG2TransportStreamIndexFile::MPEG2TransportStreamIndexFile().

00048                                                        {
00049   u_int64_t fileSize = 0; // by default
00050 
00051   if (fid != stdin) {
00052 #if !defined(_WIN32_WCE)
00053     if (fileName == NULL) {
00054 #endif
00055       if (fid != NULL && SeekFile64(fid, 0, SEEK_END) >= 0) {
00056         fileSize = (u_int64_t)TellFile64(fid);
00057         if (fileSize == (u_int64_t)-1) fileSize = 0; // TellFile64() failed
00058         SeekFile64(fid, 0, SEEK_SET);
00059       }
00060 #if !defined(_WIN32_WCE)
00061     } else {
00062       struct stat sb;
00063       if (stat(fileName, &sb) == 0) {
00064         fileSize = sb.st_size;
00065       }
00066     }
00067 #endif
00068   }
00069 
00070   return fileSize;
00071 }

FILE* OpenInputFile ( UsageEnvironment env,
char const *  fileName 
)

Definition at line 24 of file InputFile.cpp.

References env, NULL, and UsageEnvironment::setResultMsg().

Referenced by WAVAudioFileSource::createNew(), MP3FileSource::createNew(), ByteStreamFileSource::createNew(), AMRAudioFileSource::createNew(), ADTSAudioFileSource::createNew(), and MPEG2TransportStreamIndexFile::openFid().

00024                                                                  {
00025   FILE* fid;
00026 
00027   // Check for a special case file name: "stdin"
00028   if (strcmp(fileName, "stdin") == 0) {
00029     fid = stdin;
00030 #if (defined(__WIN32__) || defined(_WIN32)) && !defined(_WIN32_WCE)
00031     _setmode(_fileno(stdin), _O_BINARY); // convert to binary mode
00032 #endif
00033   } else {
00034     fid = fopen(fileName, "rb");
00035     if (fid == NULL) {
00036       env.setResultMsg("unable to open file \"",fileName, "\"");
00037     }
00038   }
00039 
00040   return fid;
00041 }

int64_t SeekFile64 ( FILE *  fid,
int64_t  offset,
int  whence 
)

Definition at line 73 of file InputFile.cpp.

References NULL.

Referenced by ADTSAudioFileSource::createNew(), ADTSAudioFileSource::doGetNextFrame(), WAVAudioFileSource::doReadFromFile(), FileIsSeekable(), GetFileSize(), ByteStreamFileSource::seekToByteAbsolute(), ByteStreamFileSource::seekToByteRelative(), ByteStreamFileSource::seekToEnd(), MPEG2TransportStreamIndexFile::seekToIndexRecord(), WAVAudioFileSource::seekToPCMByte(), MP3StreamState::seekWithinFile(), WAVAudioFileSource::setScaleFactor(), QuickTimeFileSink::setWord(), AVIFileSink::setWord(), and QuickTimeFileSink::setWord64().

00073                                                           {
00074   if (fid == NULL) return -1;
00075 
00076   clearerr(fid);
00077   fflush(fid);
00078 #if (defined(__WIN32__) || defined(_WIN32)) && !defined(_WIN32_WCE)
00079   return _lseeki64(_fileno(fid), offset, whence) == (int64_t)-1 ? -1 : 0;
00080 #else
00081 #if defined(_WIN32_WCE)
00082   return fseek(fid, (long)(offset), whence);
00083 #else
00084   return fseeko(fid, (off_t)(offset), whence);
00085 #endif
00086 #endif
00087 }

int64_t TellFile64 ( FILE *  fid  ) 

Definition at line 89 of file InputFile.cpp.

References NULL.

Referenced by QuickTimeFileSink::addAtom_hdlr2(), QuickTimeFileSink::completeOutputFile(), GetFileSize(), QuickTimeFileSink::QuickTimeFileSink(), WAVAudioFileSource::setScaleFactor(), SubsessionIOState::useFrame(), SubsessionIOState::useFrameForHinting(), and WAVAudioFileSource::WAVAudioFileSource().

00089                               {
00090   if (fid == NULL) return -1;
00091 
00092   clearerr(fid);
00093   fflush(fid);
00094 #if (defined(__WIN32__) || defined(_WIN32)) && !defined(_WIN32_WCE)
00095   return _telli64(_fileno(fid));
00096 #else
00097 #if defined(_WIN32_WCE)
00098   return ftell(fid);
00099 #else
00100   return ftello(fid);
00101 #endif
00102 #endif
00103 }


Generated on Mon Apr 29 13:29:07 2013 for live by  doxygen 1.5.2