Skip to content

Commit

Permalink
submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
notedit committed May 1, 2020
1 parent 491be4b commit f0dcbc9
Show file tree
Hide file tree
Showing 7 changed files with 1,287 additions and 2,149 deletions.
5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
module github.com/notedit/media-server-go

require (
github.com/Jeffail/gabs v1.1.1
github.com/chuckpreslar/emission v0.0.0-20170206194824-a7ddd980baf9
github.com/gofrs/uuid v3.1.0+incompatible
github.com/notedit/sdp v0.0.0-20190418080450-702b42591eb2
github.com/sanity-io/litter v1.1.0
github.com/notedit/sdp v0.0.4
)

go 1.13
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
github.com/Jeffail/gabs v1.1.1 h1:V0uzR08Hj22EX8+8QMhyI9sX2hwRu+/RJhJUmnwda/E=
github.com/Jeffail/gabs v1.1.1/go.mod h1:6xMvQMK4k33lb7GUUpaAPh6nKMmemQeg5d4gn7/bOXc=
github.com/chuckpreslar/emission v0.0.0-20170206194824-a7ddd980baf9 h1:xz6Nv3zcwO2Lila35hcb0QloCQsc38Al13RNEzWRpX4=
github.com/chuckpreslar/emission v0.0.0-20170206194824-a7ddd980baf9/go.mod h1:2wSM9zJkl1UQEFZgSd68NfCgRz1VL1jzy/RjCg+ULrs=
github.com/gofrs/uuid v3.1.0+incompatible h1:q2rtkjaKT4YEr6E1kamy0Ha4RtepWlQBedyHx0uzKwA=
github.com/gofrs/uuid v3.1.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/notedit/sdp v0.0.0-20190418080450-702b42591eb2 h1:OBlsQl9n5djQqLqwHO5gou1irbitUPwS+SfOrt3yHTU=
github.com/notedit/sdp v0.0.0-20190418080450-702b42591eb2/go.mod h1:GbICVEB3gb4OfNreIqFKFqWASbpTgrB+Q6lErFpYeaY=
github.com/sanity-io/litter v1.1.0 h1:BllcKWa3VbZmOZbDCoszYLk7zCsKHz5Beossi8SUcTc=
github.com/sanity-io/litter v1.1.0/go.mod h1:CJ0VCw2q4qKU7LaQr3n7UOSHzgEMgcGco7N/SkZQPjw=
github.com/notedit/sdp v0.0.3 h1:lcuxczyUgWKaBn49hyVu1ezOoGvVRT89Ur/eQKqyHfc=
github.com/notedit/sdp v0.0.3/go.mod h1:v7SdJxYpW6sY8RhA2KX14mmIHXKC0Kl/XrEQwaQJ7lM=
github.com/notedit/sdp v0.0.4 h1:P4L8HbZ8SfzrRDE2m3zPnkHhcSdr/0sZkapKo0lyDJs=
github.com/notedit/sdp v0.0.4/go.mod h1:v7SdJxYpW6sY8RhA2KX14mmIHXKC0Kl/XrEQwaQJ7lM=
30 changes: 14 additions & 16 deletions mediaframemultiplexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package mediaserver

import "C"
import (
"fmt"
native "github.com/notedit/media-server-go/wrapper"
"unsafe"
)

// MediaStreamDuplicater we can make a copy of the incoming stream and callback the mediaframe data
Expand Down Expand Up @@ -36,20 +34,20 @@ type overwrittenMediaFrameListener struct {

func (p *overwrittenMediaFrameListener) OnMediaFrame(frame native.MediaFrame) {

if p.multiplexer != nil && p.multiplexer.mediaframeListener != nil {
buffer := C.GoBytes(unsafe.Pointer(frame.GetData()), C.int(frame.GetLength()))
if frame.GetType() == native.MediaFrameVideo {
data, err := annexbConvert(buffer)
if err == nil {
p.multiplexer.mediaframeListener(data, frame.GetTimeStamp())
} else {
fmt.Println(err)
}
} else {
p.multiplexer.mediaframeListener(buffer, frame.GetTimeStamp())
}

}
//if p.multiplexer != nil && p.multiplexer.mediaframeListener != nil {
// buffer := C.GoBytes(unsafe.Pointer(frame.GetData()), C.int(frame.GetLength()))
// if frame.GetType() == native.MediaFrameVideo {
// data, err := annexbConvert(buffer)
// if err == nil {
// p.multiplexer.mediaframeListener(data, frame.GetTimeStamp())
// } else {
// fmt.Println(err)
// }
// } else {
// p.multiplexer.mediaframeListener(buffer, frame.GetTimeStamp())
// }
//
//}
}

// NewMediaStreamDuplicater duplicate this IncomingStreamTrack and callback the mediaframe
Expand Down
10 changes: 7 additions & 3 deletions mediaframesession.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package mediaserver

import (
"fmt"
"strings"

native "github.com/notedit/media-server-go/wrapper"
"github.com/notedit/sdp"
"strings"
)

type MediaFrameSession struct {
sources map[string]native.RTPIncomingSourceGroup
incoming *IncomingStreamTrack
session native.MediaFrameSessionFacade
}
Expand Down Expand Up @@ -37,8 +39,11 @@ func NewMediaFrameSession(media *sdp.MediaInfo) *MediaFrameSession {

session.Init(properties)
native.DeletePropertiesFacade(properties)

sources := map[string]native.RTPIncomingSourceGroup{"": session.GetIncomingSourceGroup()}
mediaSession.sources = sources
mediaSession.session = session
mediaSession.incoming = NewIncomingStreamTrack(media.GetType(), media.GetType(), native.RTPSessionToReceiver(session), map[string]native.RTPIncomingSourceGroup{"": session.GetIncomingSourceGroup()})
mediaSession.incoming = NewIncomingStreamTrack(media.GetType(), media.GetType(), native.RTPSessionToReceiver(session), sources)

return mediaSession
}
Expand All @@ -53,7 +58,6 @@ func (s *MediaFrameSession) Push(rtp []byte) {
if rtp == nil || len(rtp) == 0 {
return
}
fmt.Println("push buffer 22222", len(rtp))
s.session.OnRTPPacket(&rtp[0], len(rtp))
}

Expand Down
129 changes: 67 additions & 62 deletions wrapper/mediaserver.i
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "../media-server/include/dtls.h"
#include "../media-server/include/OpenSSL.h"
#include "../media-server/include/media.h"
#include "../media-server/include/video.h"
#include "../media-server/include/audio.h"
#include "../media-server/include/rtp.h"
#include "../media-server/include/tools.h"
#include "../media-server/include/rtpsession.h"
Expand Down Expand Up @@ -248,92 +250,95 @@ public:
void onRTPPacket(uint8_t* data, int size)
{

Log("MediaFrameSessionFacade onRTPPacket\n");

RTPHeader header;
RTPHeaderExtension extension;
// Run on thread
loop.Async([=](...) {

int len = header.Parse(data,size);
Log("MediaFrameSessionFacade onRTPPacket\n");

if (!len)
{
//Debug
Debug("-MediaFrameSessionFacade::onRTPPacket() | Could not parse RTP header\n");
return;
}
RTPHeader header;
RTPHeaderExtension extension;

if (header.extension)
{
int lsize = size;
int len = header.Parse(data,lsize);

//Parse extension
int l = extension.Parse(extMap,data+len,size-len);
//If not parsed
if (!l)
if (!len)
{
///Debug
Debug("-MediaFrameSessionFacade::onRTPPacket() | Could not parse RTP header extension\n");
//Exit
//Debug
Debug("-MediaFrameSessionFacade::onRTPPacket() | Could not parse RTP header\n");
return;
}
//Inc ini
len += l;
}

if (header.padding)
{
//Get last 2 bytes
WORD padding = get1(data,size-1);
//Ensure we have enought size
if (size-len<padding)
if (header.extension)
{
///Debug
Debug("-PCAPTransportEmulator::Run() | RTP padding is bigger than size [padding:%u,size%u]\n",padding,size);
//Ignore this try again
return;

//Parse extension
int l = extension.Parse(extMap,data+len,lsize-len);
//If not parsed
if (!l)
{
///Debug
Debug("-MediaFrameSessionFacade::onRTPPacket() | Could not parse RTP header extension\n");
//Exit
return;
}
//Inc ini
len += l;
}
//Remove from size
size -= padding;
}

if (header.padding)
{
//Get last 2 bytes
WORD padding = get1(data,lsize-1);
//Ensure we have enought size
if (size-len<padding)
{
///Debug
Debug("-PCAPTransportEmulator::Run() | RTP padding is bigger than size [padding:%u,size%u]\n",padding,size);
//Ignore this try again
return;
}
//Remove from size
lsize -= padding;
}

DWORD ssrc = header.ssrc;
BYTE type = header.payloadType;
//Get initial codec
BYTE codec = rtp.GetCodecForType(header.payloadType);

//Check codec
if (codec==RTPMap::NotFound)
{
//Exit
Error("-MediaFrameSessionFacade::onRTPPacket(%s) | RTP packet type unknown [%d]\n",MediaFrame::TypeToString(mediatype),type);
//Exit
return;
}

DWORD ssrc = header.ssrc;
BYTE type = header.payloadType;
//Get initial codec
BYTE codec = rtp.GetCodecForType(header.payloadType);

auto packet = std::make_shared<RTPPacket>(mediatype,codec,header,extension);
//Check codec
if (codec==RTPMap::NotFound)
{
//Exit
Error("-MediaFrameSessionFacade::onRTPPacket(%s) | RTP packet type unknown [%d]\n",MediaFrame::TypeToString(mediatype),type);
//Exit
return;
}

//Set the payload
packet->SetPayload(data+len,size-len);

WORD seq = packet->GetSeqNum();
auto packet = std::make_shared<RTPPacket>(mediatype,codec,header,extension);

source.media.SetSeqNum(seq);
//Set the payload
packet->SetPayload(data+len,lsize-len);

if (source.media.ssrc != ssrc) {
source.media.Reset();
source.media.ssrc = ssrc;
}
WORD seq = packet->GetSeqNum();

source.media.Update(getTimeMS(),packet->GetSeqNum(),packet->GetRTPHeader().GetSize()+packet->GetMediaLength());
source.media.SetSeqNum(seq);

packet->Dump();
if (source.media.ssrc != ssrc) {
source.media.Reset();
source.media.ssrc = ssrc;
}

source.AddPacket(packet,0);
source.media.Update(getTimeMS(),packet->GetSeqNum(),packet->GetRTPHeader().GetSize()+packet->GetMediaLength());

Debug("-MediaFrameSessionFacade::onRTPPacket() | Seq Num = %d\n", packet->GetSeqNum());
source.AddPacket(packet,0);

Debug("-MediaFrameSessionFacade::onRTPPacket() | Seq Num = %d\n", packet->GetSeqNum());

});
}

void onRTPData(uint8_t* data, int size, uint32_t timestamp)
Expand Down Expand Up @@ -957,7 +962,7 @@ private:
#define BYTE uint8_t
#define SBYTE char

%include "../media-server/include/media.h"

%include "../media-server/include/acumulator.h"


Expand Down
Loading

0 comments on commit f0dcbc9

Please sign in to comment.