Skip to content

Commit b04dbad

Browse files
committed
add rtsp library
1 parent c196e9c commit b04dbad

174 files changed

Lines changed: 14640 additions & 6 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Makefile‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ CC=$(CROSS_COMPILE)gcc
55
CXX=$(CROSS_COMPILE)g++
66

77

8-
LIBS=-ld
9-
LIBS_DIR=
8+
LIBS=-lrtmp -lpthread -lvencoder -lliveMedia -lBasicUsageEnvironment -lUsageEnvironment -lgroupsock -ldl
9+
LIBS_DIR= -Lsrc/librtmp -L./lib
1010

11-
OPT=-O2
11+
OPT=-O2 -DSOCKLEN_T=socklen_t -DNO_SSTREAM=1 -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64
1212

1313
CFLAGS =-Wall $(OPT) -DDEBUG
1414
CXXFLAGS =-Wall $(OPT) -DDEBUG
@@ -38,7 +38,7 @@ librtmp: FORCE
3838
@cd ./src/librtmp; $(MAKE) all
3939

4040
live: $(OBJS)
41-
$(CXX) -Lsrc/librtmp -L./lib -o $@ $(OBJS) -lrtmp -lpthread -lvencoder -ldl
41+
$(CXX) $(LIBS_DIR) -o $@ $(OBJS) $(LIBS)
4242

4343
help:
4444

‎src/live/H264LiveVideoSource.cpp‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* H264LiveVideoSource.cpp
3+
*
4+
* Created on: 2015年1月21日
5+
* Author: maygolf
6+
*/
7+
8+
#include "H264LiveVideoSource.h"
9+
10+
H264LiveVideoSource* H264LiveVideoSource::createNew(UsageEnvironment& env, Boolean deleteBufferOnClose, unsigned preferredFrameSize, unsigned playTimePerFrame, int fd_pipe[2])
11+
{
12+
13+
H264LiveVideoSource* videosource = new H264LiveVideoSource(env, deleteBufferOnClose, preferredFrameSize, playTimePerFrame, fd_pipe);
14+
return videosource;
15+
16+
}
17+
18+
H264LiveVideoSource::H264LiveVideoSource(UsageEnvironment& env, Boolean deleteBufferOnClose, unsigned preferredFrameSize, unsigned playTimePerFrame, int fd_pipe[2]) :
19+
FramedSource(env), fDeleteBufferOnClose(deleteBufferOnClose), fPreferredFrameSize(preferredFrameSize), fPlayTimePerFrame(playTimePerFrame), fLastPlayTime(0)
20+
{
21+
22+
}
23+
24+
H264LiveVideoSource::~H264LiveVideoSource()
25+
{
26+
27+
}
28+
29+
void H264LiveVideoSource::doGetNextFrame()
30+
{
31+
32+
}
33+

‎src/live/H264LiveVideoSource.h‎

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* H264LiveVideoSource.h
3+
*
4+
* Created on: 2015年1月21日
5+
* Author: maygolf
6+
*/
7+
#ifndef H264_LIVEVIDEOSOURCE_H
8+
#define H264_LIVEVIDEOSOURCE_H
9+
10+
#include "../live555/UsageEnvironment/UsageEnvironment.hh"
11+
#include "../live555/liveMedia/FramedSource.hh"
12+
13+
class H264LiveVideoSource: public FramedSource
14+
{
15+
16+
public:
17+
static H264LiveVideoSource* createNew(UsageEnvironment& env, Boolean deleteBufferOnClose = True, unsigned preferredFrameSize = 0, unsigned playTimePerFrame = 0,
18+
int fd_pipe[2] = NULL);
19+
20+
void seekToByteAbsolute(u_int64_t byteNumber, u_int64_t numBytesToStream = 0);
21+
// if "numBytesToStream" is >0, then we limit the stream to that number of bytes, before treating it as EOF
22+
void seekToByteRelative(int64_t offset);
23+
24+
protected:
25+
H264LiveVideoSource(UsageEnvironment& env, Boolean deleteBufferOnClose, unsigned preferredFrameSize, unsigned playTimePerFrame, int fd_pipe[2]);
26+
~H264LiveVideoSource();
27+
28+
private:
29+
// redefined virtual functions:
30+
virtual void doGetNextFrame();
31+
32+
private:
33+
int fd[2];
34+
// frame_I* fBuffer;
35+
Boolean fDeleteBufferOnClose;
36+
unsigned fPreferredFrameSize;
37+
unsigned fPlayTimePerFrame;
38+
unsigned fLastPlayTime;
39+
Boolean fLimitNumBytesToStream;
40+
u_int64_t fNumBytesToStream; // used iff "fLimitNumBytesToStream" is True
41+
42+
};
43+
44+
45+
//////////////////////////////////////////////////////////////////////////////////////////////////////
46+
//////////////////////////////////////H264LiveVideoServerMediaSubsession//////////////////////////////
47+
//////////////////////////////////////////////////////////////////////////////////////////////////////
48+
49+
50+
#include "../live555/liveMedia/H264VideoFileServerMediaSubsession.hh"
51+
52+
class H264LiveVideoServerMediaSubsession: public OnDemandServerMediaSubsession
53+
{
54+
public:
55+
static H264LiveVideoServerMediaSubsession*
56+
createNew(UsageEnvironment& env, Boolean reuseFirstSource, int fifo[2]);
57+
void checkForAuxSDPLine1();
58+
void afterPlayingDummy1();
59+
private:
60+
H264LiveVideoServerMediaSubsession(UsageEnvironment& env, Boolean reuseFirstSource, int fifo[2]);
61+
virtual ~H264LiveVideoServerMediaSubsession();
62+
63+
void setDoneFlag()
64+
{
65+
fDoneFlag = ~0;
66+
}
67+
68+
private:
69+
// redefined virtual functions
70+
virtual FramedSource* createNewStreamSource(unsigned clientSessionId, unsigned& estBitrate);
71+
virtual RTPSink* createNewRTPSink(Groupsock* rtpGroupsock, unsigned char rtpPayloadTypeIfDynamic, FramedSource* inputSource);
72+
virtual char const* getAuxSDPLine(RTPSink* rtpSink, FramedSource* inputSource);
73+
74+
private:
75+
// frame_I *pNal;
76+
int m_fifo[2];
77+
char* fAuxSDPLine;
78+
char fDoneFlag; // used when setting up "fAuxSDPLine"
79+
RTPSink* fDummyRTPSink; // ditto
80+
81+
};
82+
83+
#endif /* H264LIVEVIDEOSOURCE_H */
84+

‎src/live/Makefile‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
SOURCES +=src/live/LiveVideo.cpp src/live/H264MemReader.cpp
1+
SOURCES +=src/live/RTMPLiveVideo.cpp src/live/H264MemReader.cpp src/live/H264LiveVideoSource.cpp
22

3-
OBJS +=src/live/LiveVideo.o src/live/H264MemReader.o
3+
OBJS +=src/live/RTMPLiveVideo.o src/live/H264MemReader.o src/live/H264LiveVideoSource.o
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/**********
2+
This library is free software; you can redistribute it and/or modify it under
3+
the terms of the GNU Lesser General Public License as published by the
4+
Free Software Foundation; either version 2.1 of the License, or (at your
5+
option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
6+
7+
This library is distributed in the hope that it will be useful, but WITHOUT
8+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9+
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
10+
more details.
11+
12+
You should have received a copy of the GNU Lesser General Public License
13+
along with this library; if not, write to the Free Software Foundation, Inc.,
14+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15+
**********/
16+
// Copyright (c) 1996-2015 Live Networks, Inc. All rights reserved.
17+
// Basic Hash Table implementation
18+
// C++ header
19+
20+
#ifndef _BASIC_HASH_TABLE_HH
21+
#define _BASIC_HASH_TABLE_HH
22+
23+
#ifndef _HASH_TABLE_HH
24+
#include "HashTable.hh"
25+
#endif
26+
#ifndef _NET_COMMON_H
27+
#include <NetCommon.h> // to ensure that "uintptr_t" is defined
28+
#endif
29+
30+
// A simple hash table implementation, inspired by the hash table
31+
// implementation used in Tcl 7.6: <http://www.tcl.tk/>
32+
33+
#define SMALL_HASH_TABLE_SIZE 4
34+
35+
class BasicHashTable: public HashTable {
36+
private:
37+
class TableEntry; // forward
38+
39+
public:
40+
BasicHashTable(int keyType);
41+
virtual ~BasicHashTable();
42+
43+
// Used to iterate through the members of the table:
44+
class Iterator; friend class Iterator; // to make Sun's C++ compiler happy
45+
class Iterator: public HashTable::Iterator {
46+
public:
47+
Iterator(BasicHashTable const& table);
48+
49+
private: // implementation of inherited pure virtual functions
50+
void* next(char const*& key); // returns 0 if none
51+
52+
private:
53+
BasicHashTable const& fTable;
54+
unsigned fNextIndex; // index of next bucket to be enumerated after this
55+
TableEntry* fNextEntry; // next entry in the current bucket
56+
};
57+
58+
private: // implementation of inherited pure virtual functions
59+
virtual void* Add(char const* key, void* value);
60+
// Returns the old value if different, otherwise 0
61+
virtual Boolean Remove(char const* key);
62+
virtual void* Lookup(char const* key) const;
63+
// Returns 0 if not found
64+
virtual unsigned numEntries() const;
65+
66+
private:
67+
class TableEntry {
68+
public:
69+
TableEntry* fNext;
70+
char const* key;
71+
void* value;
72+
};
73+
74+
TableEntry* lookupKey(char const* key, unsigned& index) const;
75+
// returns entry matching "key", or NULL if none
76+
Boolean keyMatches(char const* key1, char const* key2) const;
77+
// used to implement "lookupKey()"
78+
79+
TableEntry* insertNewEntry(unsigned index, char const* key);
80+
// creates a new entry, and inserts it in the table
81+
void assignKey(TableEntry* entry, char const* key);
82+
// used to implement "insertNewEntry()"
83+
84+
void deleteEntry(unsigned index, TableEntry* entry);
85+
void deleteKey(TableEntry* entry);
86+
// used to implement "deleteEntry()"
87+
88+
void rebuild(); // rebuilds the table as its size increases
89+
90+
unsigned hashIndexFromKey(char const* key) const;
91+
// used to implement many of the routines above
92+
93+
unsigned randomIndex(uintptr_t i) const {
94+
return (unsigned)(((i*1103515245) >> fDownShift) & fMask);
95+
}
96+
97+
private:
98+
TableEntry** fBuckets; // pointer to bucket array
99+
TableEntry* fStaticBuckets[SMALL_HASH_TABLE_SIZE];// used for small tables
100+
unsigned fNumBuckets, fNumEntries, fRebuildSize, fDownShift, fMask;
101+
int fKeyType;
102+
};
103+
104+
#endif
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/**********
2+
This library is free software; you can redistribute it and/or modify it under
3+
the terms of the GNU Lesser General Public License as published by the
4+
Free Software Foundation; either version 2.1 of the License, or (at your
5+
option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
6+
7+
This library is distributed in the hope that it will be useful, but WITHOUT
8+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9+
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
10+
more details.
11+
12+
You should have received a copy of the GNU Lesser General Public License
13+
along with this library; if not, write to the Free Software Foundation, Inc.,
14+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15+
**********/
16+
// Copyright (c) 1996-2015 Live Networks, Inc. All rights reserved.
17+
// Basic Usage Environment: for a simple, non-scripted, console application
18+
// C++ header
19+
20+
#ifndef _BASIC_USAGE_ENVIRONMENT_HH
21+
#define _BASIC_USAGE_ENVIRONMENT_HH
22+
23+
#ifndef _BASIC_USAGE_ENVIRONMENT0_HH
24+
#include "BasicUsageEnvironment0.hh"
25+
#endif
26+
27+
class BasicUsageEnvironment: public BasicUsageEnvironment0 {
28+
public:
29+
static BasicUsageEnvironment* createNew(TaskScheduler& taskScheduler);
30+
31+
// redefined virtual functions:
32+
virtual int getErrno() const;
33+
34+
virtual UsageEnvironment& operator<<(char const* str);
35+
virtual UsageEnvironment& operator<<(int i);
36+
virtual UsageEnvironment& operator<<(unsigned u);
37+
virtual UsageEnvironment& operator<<(double d);
38+
virtual UsageEnvironment& operator<<(void* p);
39+
40+
protected:
41+
BasicUsageEnvironment(TaskScheduler& taskScheduler);
42+
// called only by "createNew()" (or subclass constructors)
43+
virtual ~BasicUsageEnvironment();
44+
};
45+
46+
47+
class BasicTaskScheduler: public BasicTaskScheduler0 {
48+
public:
49+
static BasicTaskScheduler* createNew(unsigned maxSchedulerGranularity = 10000/*microseconds*/);
50+
// "maxSchedulerGranularity" (default value: 10 ms) specifies the maximum time that we wait (in "select()") before
51+
// returning to the event loop to handle non-socket or non-timer-based events, such as 'triggered events'.
52+
// You can change this is you wish (but only if you know what you're doing!), or set it to 0, to specify no such maximum time.
53+
// (You should set it to 0 only if you know that you will not be using 'event triggers'.)
54+
virtual ~BasicTaskScheduler();
55+
56+
protected:
57+
BasicTaskScheduler(unsigned maxSchedulerGranularity);
58+
// called only by "createNew()"
59+
60+
static void schedulerTickTask(void* clientData);
61+
void schedulerTickTask();
62+
63+
protected:
64+
// Redefined virtual functions:
65+
virtual void SingleStep(unsigned maxDelayTime);
66+
67+
virtual void setBackgroundHandling(int socketNum, int conditionSet, BackgroundHandlerProc* handlerProc, void* clientData);
68+
virtual void moveSocketHandling(int oldSocketNum, int newSocketNum);
69+
70+
protected:
71+
unsigned fMaxSchedulerGranularity;
72+
73+
// To implement background operations:
74+
int fMaxNumSockets;
75+
fd_set fReadSet;
76+
fd_set fWriteSet;
77+
fd_set fExceptionSet;
78+
79+
private:
80+
#if defined(__WIN32__) || defined(_WIN32)
81+
// Hack to work around a bug in Windows' "select()" implementation:
82+
int fDummySocketNum;
83+
#endif
84+
};
85+
86+
#endif

0 commit comments

Comments
 (0)