00001 /********** 00002 This library is free software; you can redistribute it and/or modify it under 00003 the terms of the GNU Lesser General Public License as published by the 00004 Free Software Foundation; either version 2.1 of the License, or (at your 00005 option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.) 00006 00007 This library is distributed in the hope that it will be useful, but WITHOUT 00008 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00009 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 00010 more details. 00011 00012 You should have received a copy of the GNU Lesser General Public License 00013 along with this library; if not, write to the Free Software Foundation, Inc., 00014 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00015 **********/ 00016 // "liveMedia" 00017 // Copyright (c) 1996-2008 Live Networks, Inc. All rights reserved. 00018 // A HTTP Sink specifically for MPEG Video 00019 // Implementation 00020 00021 #include "MPEG1or2VideoHTTPSink.hh" 00022 00024 00025 MPEG1or2VideoHTTPSink* MPEG1or2VideoHTTPSink::createNew(UsageEnvironment& env, Port ourPort) { 00026 int ourSocket = -1; 00027 00028 do { 00029 int ourSocket = setUpOurSocket(env, ourPort); 00030 if (ourSocket == -1) break; 00031 00032 MPEG1or2VideoHTTPSink* newSink = new MPEG1or2VideoHTTPSink(env, ourSocket); 00033 if (newSink == NULL) break; 00034 00035 appendPortNum(env, ourPort); 00036 00037 return newSink; 00038 } while (0); 00039 00040 if (ourSocket != -1) ::closeSocket(ourSocket); 00041 return NULL; 00042 } 00043 00044 MPEG1or2VideoHTTPSink::MPEG1or2VideoHTTPSink(UsageEnvironment& env, int ourSocket) 00045 : HTTPSink(env, ourSocket), fHaveSeenFirstVSH(False) { 00046 } 00047 00048 MPEG1or2VideoHTTPSink::~MPEG1or2VideoHTTPSink() { 00049 } 00050 00051 #define VIDEO_SEQUENCE_HEADER_START_CODE 0x000001B3 00052 00053 Boolean MPEG1or2VideoHTTPSink::isUseableFrame(unsigned char* framePtr, 00054 unsigned frameSize) { 00055 // Some clients get confused if the data we give them does not start 00056 // with a 'video_sequence_header', so we ignore any frames that precede 00057 // the first 'video_sequence_header': 00058 00059 // Sanity check: a frame with < 4 bytes is never valid: 00060 if (frameSize < 4) return False; 00061 00062 if (fHaveSeenFirstVSH) return True; 00063 00064 unsigned first4Bytes 00065 = (framePtr[0]<<24)|(framePtr[1]<<16)|(framePtr[2]<<8)|framePtr[3]; 00066 00067 if (first4Bytes == VIDEO_SEQUENCE_HEADER_START_CODE) { 00068 fHaveSeenFirstVSH = True; 00069 return True; 00070 } else { 00071 return False; 00072 } 00073 }
1.5.2