Skip to content

Commit

Permalink
Merge pull request #25 from membraneframework/MS-292-bug-bash-update-…
Browse files Browse the repository at this point in the history
…to-core-v-0-11

MS-292 Update to core v0.11
  • Loading branch information
Janix4000 authored Jan 23, 2023
2 parents a92a7a0 + f8bd4f6 commit 46df82d
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 110 deletions.
25 changes: 22 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@ workflows:
version: 2
build:
jobs:
- elixir/build_test
- elixir/test
- elixir/lint
- elixir/build_test:
filters: &filters
tags:
only: /v.*/
- elixir/test:
filters:
<<: *filters
- elixir/lint:
filters:
<<: *filters
- elixir/hex_publish:
requires:
- elixir/build_test
- elixir/test
- elixir/lint
context:
- Deployment
filters:
branches:
ignore: /.*/
tags:
only: /v.*/
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
max_line_length = 100
tab_width = 2
trim_trailing_whitespace = true
5 changes: 2 additions & 3 deletions .formatter.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
inputs: [
"{lib,test,config}/**/*.{ex,exs}",
".formatter.exs",
"*.exs",
"c_src/**/*.spec.exs"
"*.exs"
],
import_deps: [:membrane_core, :bundlex, :unifex]
import_deps: [:membrane_core]
]
54 changes: 39 additions & 15 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
compile_commands.json
.gdb_history
bundlex.sh
bundlex.bat

# Dir generated by tmp_dir ExUnit tag
/tmp/

# Created by https://www.gitignore.io/api/c,vim,linux,macos,elixir,windows,visualstudiocode
# Edit at https://www.gitignore.io/?templates=c,vim,linux,macos,elixir,windows,visualstudiocode

### C ###
# Prerequisites
*.d
Expand Down Expand Up @@ -61,8 +72,11 @@ dkms.conf
erl_crash.dump
*.ez
*.beam
/config/*.secret.exs
.elixir_ls/

### Elixir Patch ###

### Linux ###
*~

Expand All @@ -79,7 +93,8 @@ erl_crash.dump
.nfs*

### macOS ###
*.DS_Store
# General
.DS_Store
.AppleDouble
.LSOverride

Expand All @@ -106,50 +121,59 @@ Temporary Items
.apdisk

### Vim ###
# swap
.sw[a-p]
.*.sw[a-p]
# session
# Swap
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]

# Session
Session.vim
# temporary
Sessionx.vim

# Temporary
.netrwhist
# auto-generated tag files
# Auto-generated tag files
tags
# Persistent undo
[._]*.un~

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

### VisualStudioCode Patch ###
# Ignore all local history of files
.history

### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
Desktop.ini
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk


compile_commands.json
.elixir_ls
.gdb_history
bundlex.sh
bundlex.bat

# End of https://www.gitignore.io/api/c,vim,linux,macos,elixir,windows,visualstudiocode
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The package can be installed by adding `membrane_sdl_plugin` to your list of dep
```elixir
def deps do
[
{:membrane_sdl_plugin, "~> 0.14.0"}
{:membrane_sdl_plugin, "~> 0.15.0"}
]
end
```
Expand Down
32 changes: 14 additions & 18 deletions examples/player.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,36 @@ Mix.install([
defmodule Example do
use Membrane.Pipeline

import Membrane.ChildrenSpec

@media_url "http://raw.githubusercontent.com/membraneframework/static/gh-pages/samples/big-buck-bunny/bun33s_720x480.h264"

@impl true
def handle_init(_opts) do
spec = %ParentSpec{
children: %{
source: %Membrane.Hackney.Source{location: @media_url, hackney_opts: [follow_redirect: true]},
parser: %Membrane.H264.FFmpeg.Parser{framerate: {25, 1}},
decoder: Membrane.H264.FFmpeg.Decoder,
player: Membrane.SDL.Player
},
links: [
link(:source) |> to(:parser) |> to(:decoder) |> to(:player)
]
}
structure =
child(:source , %Membrane.Hackney.Source{
location: @media_url,
hackney_opts: [follow_redirect: true]
})
|> child(:parser, %Membrane.H264.FFmpeg.Parser{framerate: {25, 1}})
|> child(:decoder, Membrane.H264.FFmpeg.Decoder)
|> child(:player, Membrane.SDL.Player)

# Initialize the spec and start the playback
{{:ok, spec: spec, playback: :playing}, %{}}
{[spec: structure, playback: :playing], %{}}
end

# `handle_element_end_of_stream/3` clauses handle automatic termination of the pipeline after playback is finished
@impl true
def handle_element_end_of_stream({:player, :input}, _ctx, state) do
__MODULE__.terminate(self())
{:ok, state}
{[], state}
end

@impl true
def handle_element_end_of_stream(_element, _ctx, state), do: {:ok, state}
end

# Start the pipeline
{:ok, pipeline} = Example.start_link()
monitor_ref = Process.monitor(pipeline)
{:ok, pipeline_supervisor, _pipeline} = Example.start_link()
monitor_ref = Process.monitor(pipeline_supervisor)

# Make sure the script doesn't terminate before the pipeline finishes the playback
receive do
Expand Down
51 changes: 16 additions & 35 deletions lib/membrane_sdl/player.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ defmodule Membrane.SDL.Player do
use Bunch
use Membrane.Sink

require Membrane.Logger
require Unifex.CNode

alias Membrane.{Buffer, Time}
Expand All @@ -15,72 +16,52 @@ defmodule Membrane.SDL.Player do
# The measured latency needed to show a frame on a screen.
@latency 20 |> Time.milliseconds()

def_input_pad :input, caps: RawVideo, demand_unit: :buffers
def_input_pad :input, accepted_format: RawVideo, demand_unit: :buffers

@impl true
def handle_init(_options) do
def handle_init(_options, _ctx) do
state = %{cnode: nil, timer_started?: false}
{{:ok, latency: @latency}, state}
{[latency: @latency], state}
end

@impl true
def handle_stopped_to_prepared(_ctx, state) do
def handle_setup(_ctx, state) do
{:ok, cnode} = CNode.start_link(:player)
{:ok, %{state | cnode: cnode}}

{[], %{state | cnode: cnode}}
end

@impl true
def handle_caps(:input, caps, ctx, state) do
def handle_stream_format(:input, stream_format, ctx, state) do
%{input: input} = ctx.pads
%{cnode: cnode} = state

if !input.caps || caps == input.caps do
:ok = CNode.call(cnode, :create, [caps.width, caps.height])
{:ok, state}
if !input.stream_format || stream_format == input.stream_format do
:ok = CNode.call(cnode, :create, [stream_format.width, stream_format.height])
{[], state}
else
raise "Caps have changed while playing. This is not supported."
raise "Stream format have changed while playing. This is not supported."
end
end

@impl true
def handle_start_of_stream(:input, %{pads: %{input: %{caps: nil}}}, _state) do
raise "No caps before start of stream"
end

@impl true
def handle_start_of_stream(:input, ctx, state) do
use Ratio
{nom, denom} = ctx.pads.input.caps.framerate
{nom, denom} = ctx.pads.input.stream_format.framerate
timer = {:demand_timer, Time.seconds(denom) <|> nom}

{{:ok, demand: :input, start_timer: timer}, %{state | timer_started?: true}}
{[demand: :input, start_timer: timer], %{state | timer_started?: true}}
end

@impl true
def handle_write(:input, %Buffer{payload: payload}, _ctx, state) do
payload = Membrane.Payload.to_binary(payload)
:ok = CNode.call(state.cnode, :display_frame, [payload])
{:ok, state}
{[], state}
end

@impl true
def handle_tick(:demand_timer, _ctx, state) do
{{:ok, demand: :input}, state}
end

@impl true
def handle_playing_to_prepared(_ctx, %{timer_started?: true} = state) do
{{:ok, stop_timer: :demand_timer}, %{state | timer_started?: false}}
end

@impl true
def handle_playing_to_prepared(_ctx, state) do
{:ok, state}
end

@impl true
def handle_prepared_to_stopped(_ctx, state) do
:ok = state.cnode |> CNode.stop()
{:ok, %{state | cnode: nil}}
{[demand: :input], state}
end
end
10 changes: 5 additions & 5 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Membrane.SDL.Plugin.MixProject do
use Mix.Project

@version "0.14.0"
@version "0.15.0"
@github_url "https://github.com/membraneframework/membrane_sdl_plugin"

def project do
Expand Down Expand Up @@ -55,13 +55,13 @@ defmodule Membrane.SDL.Plugin.MixProject do

defp deps do
[
{:membrane_core, "~> 0.10.0"},
{:membrane_common_c, "~> 0.13.0"},
{:membrane_core, "~> 0.11.0"},
{:membrane_common_c, "~> 0.14.0"},
{:membrane_raw_video_format, "~> 0.2.0"},
{:unifex, "~> 1.0"},
# Testing
{:membrane_h264_ffmpeg_plugin, "~> 0.17", only: :test},
{:membrane_hackney_plugin, "~> 0.7", only: :test},
{:membrane_h264_ffmpeg_plugin, "~> 0.25.0", only: :test},
{:membrane_hackney_plugin, "~> 0.9.0", only: :test},
# Development
{:ex_doc, "~> 0.28", only: :dev, runtime: false},
{:dialyxir, "~> 1.1", only: :dev, runtime: false},
Expand Down
Loading

0 comments on commit 46df82d

Please sign in to comment.