[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] /srv/bzr/gnash/rtmp r9741: figure out the file type.
From: |
rob |
Subject: |
[Gnash-commit] /srv/bzr/gnash/rtmp r9741: figure out the file type. |
Date: |
Mon, 17 Nov 2008 10:09:02 -0700 |
User-agent: |
Bazaar (1.5) |
------------------------------------------------------------
revno: 9741
committer: address@hidden
branch nick: rtmp
timestamp: Mon 2008-11-17 10:09:02 -0700
message:
figure out the file type.
modified:
libnet/diskstream.cpp
libnet/diskstream.h
=== modified file 'libnet/diskstream.cpp'
--- a/libnet/diskstream.cpp 2008-11-15 17:09:19 +0000
+++ b/libnet/diskstream.cpp 2008-11-17 17:09:02 +0000
@@ -32,6 +32,7 @@
#include "network.h"
#include "buffer.h"
+#include "amf.h"
#include "log.h"
#include "cque.h"
#include "diskstream.h"
@@ -43,6 +44,7 @@
using namespace gnash;
using namespace std;
+using namespace amf;
/// \namespace gnash
/// This is the main namespace for Gnash and it's libraries.
@@ -469,7 +471,8 @@
}
// Stream a single "real-time" source.
-bool DiskStream::multicast(const string & /*filespec*/)
+bool
+DiskStream::multicast(const string & /*filespec*/)
{
// GNASH_REPORT_FUNCTION;
@@ -478,6 +481,110 @@
return true; // Default to true
}
+DiskStream::filetype_e
+DiskStream::determineFileType()
+{
+// GNASH_REPORT_FUNCTION;
+
+ return(determineFileType(_filespec));
+}
+
+DiskStream::filetype_e
+DiskStream::determineFileType(const string &filespec)
+{
+// GNASH_REPORT_FUNCTION;
+
+ if (filespec.empty()) {
+ return FILETYPE_NONE;
+ }
+
+ string::size_type pos;
+ pos = filespec.rfind(".");
+ if (pos != string::npos) {
+ string suffix = filespec.substr(pos, filespec.size());
+ if (suffix == "html") {
+ _filetype = FILETYPE_HTML;
+ }
+ if (suffix == "ogg") {
+ _filetype = FILETYPE_OGG;
+ }
+ if (suffix == "swf") {
+ _filetype = FILETYPE_SWF;
+ }
+ if (suffix == "flv") {
+ _filetype = FILETYPE_FLV;
+ }
+ if (suffix == "mp3") {
+ _filetype = FILETYPE_MP3;
+ }
+ if (suffix == "flac") {
+ _filetype = FILETYPE_FLAC;
+ }
+ }
+
+ return _filetype;
+}
+
+DiskStream::filetype_e
+DiskStream::determineFileType( boost::uint8_t *data)
+{
+// GNASH_REPORT_FUNCTION;
+
+ if (data == 0) {
+ return FILETYPE_NONE;
+ }
+
+ // JPEG, offset 6 bytes, read the string JFIF
+ if (memcpy(data + 6, "JFIF", 4) == 0) {
+ return FILETYPE_NONE;
+ }
+ // SWF, offset 0, read the string FWS
+ if (memcpy(data, "SWF", 3) == 0) {
+ return FILETYPE_SWF;
+ }
+ // compressed SWF, offset 0, read the string CWS
+ // FLV, offset 0, read the string FLV
+ // PNG, offset 0, read the string PNG
+ if (memcpy(data, "PNG", 3) == 0) {
+ return FILETYPE_PNG;
+ }
+ // Ogg, offset 0, read the string OggS
+ if (memcpy(data, "OggS", 4) == 0) {
+ return FILETYPE_OGG;
+ }
+ // Theora, offset 28, read string theora
+ if (memcpy(data + 28, "theora", 6) == 0) {
+ return FILETYPE_THEORA;
+ }
+ // FLAC, offset 28, read string FLAC
+ if (memcpy(data + 28, "FLAC", 4) == 0) {
+ return FILETYPE_FLAC;
+ }
+ // Vorbis, offset 28, read string vorbis
+ if (memcpy(data + 28, "vorbis", 6) == 0) {
+ return FILETYPE_VORBIS;
+ }
+ // MP3, offset 0, read string ID3
+ if (memcpy(data, "ID3", 3) == 0) {
+ return FILETYPE_MP3;
+ }
+
+ // HTML
+ // offset 0, read string "\<!doctype\ html"
+ // offset 0, read string "\<head"
+ // offset 0, read string "\<title"
+ // offset 0, read string "\<html"
+ if (memcpy(data, "ID3", 3) == 0) {
+ return FILETYPE_HTML;
+ }
+
+ // XML, offset 0, read string "\<?xml"
+ if (memcpy(data, "<?xml", 5) == 0) {
+ return FILETYPE_XML;
+ }
+
+}
+
/// \brief Dump the internal data of this class in a human readable form.
/// @remarks This should only be used for debugging purposes.
void
=== modified file 'libnet/diskstream.h'
--- a/libnet/diskstream.h 2008-11-15 03:17:57 +0000
+++ b/libnet/diskstream.h 2008-11-17 17:09:02 +0000
@@ -56,7 +56,27 @@
MULTICAST,
DONE
} state_e;
-
+
+ typedef enum {
+ FILETYPE_NONE,
+ FILETYPE_SWF,
+ FILETYPE_HTML,
+ FILETYPE_PNG,
+ FILETYPE_JPEG,
+ FILETYPE_GIF,
+ FILETYPE_MP3,
+ FILETYPE_MP4,
+ FILETYPE_OGG,
+ FILETYPE_VORBIS,
+ FILETYPE_THEORA,
+ FILETYPE_DIRAC,
+ FILETYPE_TEXT,
+ FILETYPE_FLV,
+ FILETYPE_VP6,
+ FILETYPE_XML,
+ FILETYPE_FLAC
+ } filetype_e;
+
DiskStream();
DiskStream(const std::string &filespec);
DiskStream(const std::string &filespec, int netfd);
@@ -182,6 +202,8 @@
/// @return A value that is the size of the file in bytes.
size_t getFileSize() { return _filesize; };
+ filetype_e getFileType() { return _filetype; };
+
/// \brief Get the time of the last access.
///
/// @return A real pointer to the struct timespec of the last access.
@@ -244,7 +266,19 @@
/// The offset within the file of the current memory
/// page.
off_t _offset;
-
+
+ /// \brief An internal routine used to extract the type of file.
+ ///
+ /// @param filespec An optional filename to extract the type from.
+ ///
+ /// @return an AMF filetype
+ filetype_e determineFileType();
+ filetype_e determineFileType( boost::uint8_t *data);
+ filetype_e determineFileType(const std::string &filespec);
+
+
+ filetype_e _filetype;
+
struct timespec _last_access;
#ifdef USE_STATS_CACHE
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] /srv/bzr/gnash/rtmp r9741: figure out the file type.,
rob <=