winlin

Merge branch 'srs.master'

1 /* 1 /*
  2 +# see: https://github.com/winlinvip/simple-rtmp-server/issues/190
2 # see: https://github.com/winlinvip/simple-rtmp-server/wiki/v1_CN_SrsLinuxArm 3 # see: https://github.com/winlinvip/simple-rtmp-server/wiki/v1_CN_SrsLinuxArm
3 g++ -g -O0 -o jmp_sp jmp_sp.cpp 4 g++ -g -O0 -o jmp_sp jmp_sp.cpp
4 arm-linux-gnueabi-g++ -g -o jmp_sp jmp_sp.cpp -static 5 arm-linux-gnueabi-g++ -g -o jmp_sp jmp_sp.cpp -static
@@ -14,15 +15,13 @@ void func1() @@ -14,15 +15,13 @@ void func1()
14 { 15 {
15 #if defined(__amd64__) || defined(__x86_64__) 16 #if defined(__amd64__) || defined(__x86_64__)
16 register long int rsp0 asm("rsp"); 17 register long int rsp0 asm("rsp");
17 - printf("in func1, rsp=%#lx, longjmp to func0\n", rsp0);  
18 18
19 - longjmp(env_func1, 0x101);  
20 -  
21 - printf("func1 terminated\n"); 19 + int ret = setjmp(env_func1);
  20 + printf("setjmp func0 ret=%d, rsp=%#lx\n", ret, rsp0);
22 #endif 21 #endif
23 } 22 }
24 23
25 -void func0(int* pv0, int* pv1) 24 +void func0()
26 { 25 {
27 /** 26 /**
28 the definition of jmp_buf: 27 the definition of jmp_buf:
@@ -63,6 +62,8 @@ void func0(int* pv0, int* pv1) @@ -63,6 +62,8 @@ void func0(int* pv0, int* pv1)
63 printf("env[%d]=%#x, ", i, (int)env_func1[0].__jmpbuf[i]); 62 printf("env[%d]=%#x, ", i, (int)env_func1[0].__jmpbuf[i]);
64 } 63 }
65 printf("\n"); 64 printf("\n");
  65 +
  66 + func1();
66 #else 67 #else
67 /** 68 /**
68 /usr/arm-linux-gnueabi/include/bits/setjmp.h 69 /usr/arm-linux-gnueabi/include/bits/setjmp.h
@@ -84,6 +85,24 @@ void func0(int* pv0, int* pv1) @@ -84,6 +85,24 @@ void func0(int* pv0, int* pv1)
84 10-26: d8-d15 17words 85 10-26: d8-d15 17words
85 27: fpscr 86 27: fpscr
86 */ 87 */
  88 + /**
  89 + For example, on raspberry-pi, armv6 cpu:
  90 + (gdb) x /64 env_func1[0].__jmpbuf
  91 + v1, 0: 0x00 0x00 0x00 0x00
  92 + v2, 1: 0x00 0x00 0x00 0x00
  93 + v3, 2: 0x2c 0x84 0x00 0x00
  94 + v4, 3: 0x00 0x00 0x00 0x00
  95 + v5, 4: 0x00 0x00 0x00 0x00
  96 + v6, 5: 0x00 0x00 0x00 0x00
  97 + sl, 6: 0x00 0xf0 0xff 0xb6
  98 + fp, 7: 0x9c 0xfb 0xff 0xbe
  99 + sp, 8: 0x88 0xfb 0xff 0xbe
  100 + pc, 9: 0x08 0x85 0x00 0x00
  101 + (gdb) p /x $sp
  102 + $5 = 0xbefffb88
  103 + (gdb) p /x $pc
  104 + $4 = 0x850c
  105 + */
87 int ret = setjmp(env_func1); 106 int ret = setjmp(env_func1);
88 printf("setjmp func1 ret=%d\n", ret); 107 printf("setjmp func1 ret=%d\n", ret);
89 108
@@ -105,10 +124,7 @@ int main(int argc, char** argv) { @@ -105,10 +124,7 @@ int main(int argc, char** argv) {
105 (int)sizeof(long int), (int)sizeof(long), (int)sizeof(int)); 124 (int)sizeof(long int), (int)sizeof(long), (int)sizeof(int));
106 #endif 125 #endif
107 126
108 - int pv0 = 0xf0;  
109 - int pv1 = 0xf1;  
110 - func0(&pv0, &pv1);  
111 - func1(); 127 + func0();
112 128
113 printf("terminated\n"); 129 printf("terminated\n");
114 130
@@ -6,7 +6,7 @@ else @@ -6,7 +6,7 @@ else
6 ST_ALL = objs/srs_flv_parser \ 6 ST_ALL = objs/srs_flv_parser \
7 objs/srs_flv_injecter objs/srs_publish objs/srs_play \ 7 objs/srs_flv_injecter objs/srs_publish objs/srs_play \
8 objs/srs_ingest_flv objs/srs_ingest_rtmp objs/srs_detect_rtmp \ 8 objs/srs_ingest_flv objs/srs_ingest_rtmp objs/srs_detect_rtmp \
9 - objs/srs_bandwidth_check 9 + objs/srs_bandwidth_check objs/srs_h264_raw_publish
10 endif 10 endif
11 11
12 .PHONY: default clean help ssl nossl 12 .PHONY: default clean help ssl nossl
@@ -23,6 +23,7 @@ help: @@ -23,6 +23,7 @@ help:
23 @echo " srs_flv_parser parse flv file, print detail info." 23 @echo " srs_flv_parser parse flv file, print detail info."
24 @echo " srs_flv_injecter inject keyframes information to metadata." 24 @echo " srs_flv_injecter inject keyframes information to metadata."
25 @echo " srs_publish publish program using srs-librtmp" 25 @echo " srs_publish publish program using srs-librtmp"
  26 + @echo " srs_h264_raw_publish publish raw h.264 stream to SSR by srs-librtmp"
26 @echo " srs_play play program using srs-librtmp" 27 @echo " srs_play play program using srs-librtmp"
27 @echo " srs_ingest_flv ingest flv file and publish to RTMP server." 28 @echo " srs_ingest_flv ingest flv file and publish to RTMP server."
28 @echo " srs_ingest_rtmp ingest RTMP and publish to RTMP server." 29 @echo " srs_ingest_rtmp ingest RTMP and publish to RTMP server."
@@ -81,6 +82,9 @@ objs/srs_flv_injecter: srs_flv_injecter.c $(SRS_RESEARCH_DEPS) $(SRS_LIBRTMP_I) @@ -81,6 +82,9 @@ objs/srs_flv_injecter: srs_flv_injecter.c $(SRS_RESEARCH_DEPS) $(SRS_LIBRTMP_I)
81 objs/srs_publish: srs_publish.c $(SRS_RESEARCH_DEPS) $(SRS_LIBRTMP_I) $(SRS_LIBRTMP_L) $(SRS_LIBSSL_L) 82 objs/srs_publish: srs_publish.c $(SRS_RESEARCH_DEPS) $(SRS_LIBRTMP_I) $(SRS_LIBRTMP_L) $(SRS_LIBSSL_L)
82 $(GCC) srs_publish.c $(SRS_LIBRTMP_L) $(SRS_LIBSSL_L) $(EXTRA_CXX_FLAG) -o objs/srs_publish 83 $(GCC) srs_publish.c $(SRS_LIBRTMP_L) $(SRS_LIBSSL_L) $(EXTRA_CXX_FLAG) -o objs/srs_publish
83 84
  85 +objs/srs_h264_raw_publish: srs_h264_raw_publish.c $(SRS_RESEARCH_DEPS) $(SRS_LIBRTMP_I) $(SRS_LIBRTMP_L) $(SRS_LIBSSL_L)
  86 + $(GCC) srs_h264_raw_publish.c $(SRS_LIBRTMP_L) $(SRS_LIBSSL_L) $(EXTRA_CXX_FLAG) -o objs/srs_h264_raw_publish
  87 +
84 objs/srs_play: srs_play.c $(SRS_RESEARCH_DEPS) $(SRS_LIBRTMP_I) $(SRS_LIBRTMP_L) $(SRS_LIBSSL_L) 88 objs/srs_play: srs_play.c $(SRS_RESEARCH_DEPS) $(SRS_LIBRTMP_I) $(SRS_LIBRTMP_L) $(SRS_LIBSSL_L)
85 $(GCC) srs_play.c $(SRS_LIBRTMP_L) $(SRS_LIBSSL_L) $(EXTRA_CXX_FLAG) -o objs/srs_play 89 $(GCC) srs_play.c $(SRS_LIBRTMP_L) $(SRS_LIBSSL_L) $(EXTRA_CXX_FLAG) -o objs/srs_play
86 90
  1 +/*
  2 +The MIT License (MIT)
  3 +
  4 +Copyright (c) 2013-2014 winlin
  5 +
  6 +Permission is hereby granted, free of charge, to any person obtaining a copy of
  7 +this software and associated documentation files (the "Software"), to deal in
  8 +the Software without restriction, including without limitation the rights to
  9 +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10 +the Software, and to permit persons to whom the Software is furnished to do so,
  11 +subject to the following conditions:
  12 +
  13 +The above copyright notice and this permission notice shall be included in all
  14 +copies or substantial portions of the Software.
  15 +
  16 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18 +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19 +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20 +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21 +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22 +*/
  23 +/**
  24 +gcc srs_h264_raw_publish.c ../../objs/lib/srs_librtmp.a -g -O0 -lstdc++ -o srs_h264_raw_publish
  25 +*/
  26 +
  27 +#include <stdio.h>
  28 +#include <stdlib.h>
  29 +#include <unistd.h>
  30 +
  31 +#include "../../objs/include/srs_librtmp.h"
  32 +
  33 +#define srs_trace(msg, ...) printf(msg, ##__VA_ARGS__);printf("\n")
  34 +
  35 +int main(int argc, char** argv)
  36 +{
  37 + srs_rtmp_t rtmp;
  38 +
  39 + // packet data
  40 + int type, size;
  41 + u_int32_t timestamp = 0;
  42 + char* data;
  43 +
  44 + srs_trace("publish raw h.264 as rtmp stream to server like FMLE/FFMPEG/Encoder");
  45 + srs_trace("srs(simple-rtmp-server) client librtmp library.");
  46 + srs_trace("version: %d.%d.%d\n", srs_version_major(), srs_version_minor(), srs_version_revision());
  47 +
  48 + rtmp = srs_rtmp_create("rtmp://127.0.0.1:1935/live/livestream");
  49 +
  50 + if (srs_simple_handshake(rtmp) != 0) {
  51 + srs_trace("simple handshake failed.");
  52 + goto rtmp_destroy;
  53 + }
  54 + srs_trace("simple handshake success");
  55 +
  56 + if (srs_connect_app(rtmp) != 0) {
  57 + srs_trace("connect vhost/app failed.");
  58 + goto rtmp_destroy;
  59 + }
  60 + srs_trace("connect vhost/app success");
  61 +
  62 + if (srs_publish_stream(rtmp) != 0) {
  63 + srs_trace("publish stream failed.");
  64 + goto rtmp_destroy;
  65 + }
  66 + srs_trace("publish stream success");
  67 +
  68 + for (;;) {
  69 + type = SRS_RTMP_TYPE_VIDEO;
  70 + timestamp += 40;
  71 + size = 4096;
  72 + data = (char*)malloc(4096);
  73 +
  74 + if (srs_write_packet(rtmp, type, timestamp, data, size) != 0) {
  75 + goto rtmp_destroy;
  76 + }
  77 + srs_trace("sent packet: type=%s, time=%d, size=%d", srs_type2string(type), timestamp, size);
  78 +
  79 + usleep(40 * 1000);
  80 + }
  81 +
  82 +rtmp_destroy:
  83 + srs_rtmp_destroy(rtmp);
  84 +
  85 + return 0;
  86 +}
@@ -132,6 +132,7 @@ file @@ -132,6 +132,7 @@ file
132 ..\..\research\librtmp\srs_detect_rtmp.c, 132 ..\..\research\librtmp\srs_detect_rtmp.c,
133 ..\..\research\librtmp\srs_flv_injecter.c, 133 ..\..\research\librtmp\srs_flv_injecter.c,
134 ..\..\research\librtmp\srs_flv_parser.c, 134 ..\..\research\librtmp\srs_flv_parser.c,
  135 + ..\..\research\librtmp\srs_h264_raw_publish.c,
135 ..\..\research\librtmp\srs_ingest_flv.c, 136 ..\..\research\librtmp\srs_ingest_flv.c,
136 ..\..\research\librtmp\srs_ingest_rtmp.c, 137 ..\..\research\librtmp\srs_ingest_rtmp.c,
137 ..\..\research\librtmp\srs_play.c, 138 ..\..\research\librtmp\srs_play.c,