Skip to content

Commit

Permalink
rtsp reader fixing Axis
Browse files Browse the repository at this point in the history
  • Loading branch information
maxlapshin committed Oct 8, 2012
1 parent b629e7d commit d42005d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
7 changes: 6 additions & 1 deletion Makefile
Expand Up @@ -13,7 +13,7 @@ install: all


app: deps/cowboy
@ERL_LIBS=apps:deps erl -make
@./rebar compile

deps/cowboy:
@./rebar get-deps
Expand All @@ -34,6 +34,11 @@ vagrant:
vagrant up
vagrant ssh -c "sudo -s /etc/init.d/flussonic start"


# check_public:
# vagrant destroy -f


start:
mkdir -p log/pipe
run_erl -daemon log/pipe/ log/ "exec make run"
Expand Down
16 changes: 13 additions & 3 deletions Vagrantfile
Expand Up @@ -2,16 +2,27 @@
# vi: set ft=ruby :

Vagrant::Config.run do |config|


config.vm.define :precise64 do |conf|
conf.vm.box = "precise64"
conf.vm.box_url = "http://files.vagrantup.com/precise64.box"
conf.vm.provision :shell, :path => "manifests/precise64.sh"
end

# config.vm.define :squeeze64 do |conf|
# conf.vm.box = "squeeze64"
# conf.vm.box_url = "http://puppetlabs.s3.amazonaws.com/pub/squeeze64.box"
# end

# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.

# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "precise64"

# The url from where the 'config.vm.box' box will be fetched if it
# doesn't already exist on the user's system.
config.vm.box_url = "http://files.vagrantup.com/precise64.box"

# Boot with a GUI so you can see the screen. (Default is headless)
# config.vm.boot_mode = :gui
Expand Down Expand Up @@ -62,7 +73,6 @@ Vagrant::Config.run do |config|
# puppet.manifest_file = "precise64.pp"
# end

config.vm.provision :shell, :path => "manifests/precise64.sh"

# Enable provisioning with chef solo, specifying a cookbooks path, roles
# path, and data_bags path (all relative to this Vagrantfile), and adding
Expand Down
14 changes: 10 additions & 4 deletions apps/rtsp/src/rtsp_reader.erl
Expand Up @@ -83,29 +83,35 @@ try_read0(#rtsp{proto = Proto, url = URL} = RTSP) ->
{ok, 200, _, _} = rtsp_protocol:call(Proto, 'OPTIONS', []),
{ok, DescribeCode, DescribeHeaders, SDP} = rtsp_protocol:call(Proto, 'DESCRIBE', [{'Accept', <<"application/sdp">>}]),
DescribeCode == 401 andalso throw({rtsp, denied, 401}),
DescribeCode == 404 andalso throw({stop, not_found, 404}),
DescribeCode == 404 andalso throw({rtps, not_found, 404}),
ContentBase = parse_content_base(DescribeHeaders, URL, RTSP#rtsp.content_base),

MI1 = #media_info{streams = Streams1} = sdp:decode(SDP),
MI2 = MI1#media_info{streams = [S || #stream_info{content = Content, codec = Codec} = S <- Streams1,
(Content == audio orelse Content == video) andalso Codec =/= undefined]},
MediaInfo = MI2,
lists:foldl(fun(#stream_info{options = Opt, track_id = TrackId} = StreamInfo, N) ->
Track = ContentBase ++ proplists:get_value(control, Opt),
Control = proplists:get_value(control, Opt),
Track = control_url(ContentBase, Control),
Transport = io_lib:format("RTP/AVP/TCP;unicast;interleaved=~B-~B", [N, N+1]),
rtsp_protocol:call(Proto, 'SETUP', [{'Transport', Transport},{url, Track}]),
{ok, SetupCode, _, _} = rtsp_protocol:call(Proto, 'SETUP', [{'Transport', Transport},{url, Track}]),
SetupCode == 200 orelse throw({rtsp, failed_setup, {SetupCode, Track}}),
rtsp_protocol:add_channel(Proto, TrackId-1, StreamInfo),
N + 2
end, 0, MediaInfo#media_info.streams),

{ok, 200, PlayHeaders, _} = rtsp_protocol:call(Proto, 'PLAY', []),
{ok, PlayCode, PlayHeaders, _} = rtsp_protocol:call(Proto, 'PLAY', []),
PlayCode == 200 orelse throw({rtsp, rejected_play, PlayCode}),
RtpInfo = parse_rtp_info(PlayHeaders),

[rtsp_protocol:sync(Proto, N, Sync) || {N, Sync} <- lists:zip(lists:seq(0,length(RtpInfo)-1),RtpInfo)],

RTSP#rtsp{content_base = ContentBase, media_info = MediaInfo}.


% Axis cameras have "rtsp://192.168.0.1:554/axis-media/media.amp/trackID=1" in SDP
control_url(_ContentBase, "rtsp://" ++ _ = ControlUrl) -> ControlUrl;
control_url(ContentBase, ControlUrl) -> ContentBase ++ ControlUrl.

parse_content_base(Headers, URL, OldContentBase) ->
case proplists:get_value('Content-Base', Headers) of
Expand Down

0 comments on commit d42005d

Please sign in to comment.