├── README ├── RELEASENOTES ├── .gitignore ├── tools └── linsys │ └── sdipermissions.sh ├── filters ├── video │ ├── cc.h │ ├── video.h │ ├── x86 │ │ ├── vfilter.h │ │ └── vfilter.asm │ └── dither.h └── audio │ ├── audio.h │ ├── 337m │ └── 337m.c │ └── audio.c ├── output ├── output.h └── ip │ └── ip.c ├── mux ├── mux.h └── smoothing.c ├── encoders ├── video │ └── video.h ├── audio │ ├── audio.h │ ├── mp2 │ │ └── twolame.c │ └── lavc │ │ └── lavc.c └── smoothing.c ├── common ├── lavc.h ├── network │ ├── udp │ │ ├── udp.h │ │ └── udp.c │ └── network.h ├── linsys │ ├── util.h │ ├── master.h │ ├── pci_ids.h │ └── asi.h ├── lavc.c ├── bs_read.h └── bitstream.h ├── input ├── input.h └── sdi │ ├── decklink │ └── include │ │ ├── DeckLinkAPIVersion.h │ │ ├── DeckLinkAPIDiscovery.h │ │ ├── LinuxCOM.h │ │ ├── DeckLinkAPITypes.h │ │ ├── DeckLinkAPIDispatch.cpp │ │ ├── DeckLinkAPIModes.h │ │ └── DeckLinkAPIConfiguration.h │ ├── x86 │ ├── sdi.h │ └── sdi.asm │ ├── ancillary.h │ ├── vbi.h │ ├── sdi.h │ ├── linsys │ └── include │ │ ├── sdi.h │ │ ├── sdiaudio.h │ │ └── sdivideo.h │ └── sdi.c ├── Makefile └── obecli.h /README: -------------------------------------------------------------------------------- 1 | Open Broadcast Encoder Realtime - 0.1 2 | 3 | See the wiki at http://wiki.obe.tv for more information on how to use OBE. 4 | -------------------------------------------------------------------------------- /RELEASENOTES: -------------------------------------------------------------------------------- 1 | OBE-RT 0.1 Release Notes 2 | 3 | ** Suitability ** 4 | 5 | OBE-RT is suitable for production use. It has been deployed extensively. 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.a 3 | *.diff 4 | *.orig 5 | *.rej 6 | *.dll* 7 | *.exe 8 | *.def 9 | *.lib 10 | *.pdb 11 | *.mo 12 | *.o 13 | *.patch 14 | *.pc 15 | *.pot 16 | *.so* 17 | *.dylib 18 | .*.swp 19 | .depend 20 | .DS_Store 21 | config.h 22 | config.mak 23 | config.log 24 | x264_config.h 25 | x264 26 | checkasm 27 | 28 | *.264 29 | *.h264 30 | *.2pass 31 | *.ffindex 32 | *.avs 33 | *.mkv 34 | *.flv 35 | *.mp4 36 | *.y4m 37 | *.yuv 38 | *.log 39 | *.mbtree 40 | *.temp 41 | *.pyc 42 | 43 | .digress_x264 44 | dataDec.txt 45 | log.dec 46 | 47 | obecli 48 | -------------------------------------------------------------------------------- /tools/linsys/sdipermissions.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ $EUID -ne 0 ]]; 4 | then 5 | echo "This script must be run as root" 1>&2 6 | exit 1 7 | fi 8 | 9 | sysvideo="/sys/class/sdivideo" 10 | sysaudio="/sys/class/sdiaudio" 11 | 12 | for i in `seq 0 16`; 13 | do 14 | if [ -c "/dev/sdivideorx$i" ] 15 | then 16 | echo "Setting permissions for card $i" 1>&2 17 | chmod 774 "/dev/sdivideorx$i" 18 | chmod 774 "/dev/sdiaudiorx$i" 19 | chmod 776 "${sysvideo}/sdivideorx$i/buffers" 20 | chmod 776 "${sysvideo}/sdivideorx$i/bufsize" 21 | chmod 776 "${sysvideo}/sdivideorx$i/mode" 22 | chmod -f 776 "${sysvideo}/sdivideorx$i/vanc" 23 | chmod 776 "${sysaudio}/sdiaudiorx$i/buffers" 24 | chmod 776 "${sysaudio}/sdiaudiorx$i/bufsize" 25 | chmod 776 "${sysaudio}/sdiaudiorx$i/channels" 26 | chmod 776 "${sysaudio}/sdiaudiorx$i/sample_size" 27 | else 28 | if [ "$i" = "0" ] 29 | then 30 | echo "No Linsys/DVEO SDI cards found" 1>&2 31 | fi 32 | exit 1 33 | fi 34 | done 35 | -------------------------------------------------------------------------------- /filters/video/cc.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * cc.h: caption encapsulation headers 3 | ***************************************************************************** 4 | * Copyright (C) 2010-2011 Open Broadcast Systems Ltd 5 | * 6 | * Authors: Kieran Kunhya 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | *****************************************************************************/ 23 | 24 | #ifndef OBE_FILTERS_VIDEO_CC_H 25 | #define OBE_FILTERS_VIDEO_CC_H 26 | 27 | int write_608_cc( obe_user_data_t *user_data, obe_raw_frame_t *raw_frame ); 28 | int read_cdp( obe_user_data_t *user_data ); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /output/output.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * output.h : OBE output headers 3 | ***************************************************************************** 4 | * Copyright (C) 2010 Open Broadcast Systems Ltd. 5 | * 6 | * Authors: Kieran Kunhya 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | *****************************************************************************/ 23 | 24 | #ifndef OBE_OUTPUT_H 25 | #define OBE_OUTPUT_H 26 | 27 | typedef struct 28 | { 29 | void* (*open_output)( void *ptr ); 30 | } obe_output_func_t; 31 | 32 | extern const obe_output_func_t ip_output; 33 | 34 | #endif /* OBE_OUTPUT_H */ 35 | -------------------------------------------------------------------------------- /mux/mux.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * mux.h : OBE muxing headers 3 | ***************************************************************************** 4 | * Copyright (C) 2010 Open Broadcast Systems Ltd. 5 | * 6 | * Authors: Kieran Kunhya 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | *****************************************************************************/ 23 | 24 | #ifndef OBE_MUX_H 25 | #define OBE_MUX_H 26 | 27 | typedef struct 28 | { 29 | void* (*open_muxer)( void *ptr ); 30 | } obe_mux_func_t; 31 | 32 | typedef struct 33 | { 34 | obe_t *h; 35 | obe_device_t *device; 36 | int num_output_streams; 37 | obe_output_stream_t *output_streams; 38 | } obe_mux_params_t; 39 | 40 | extern const obe_mux_func_t ts_muxer; 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /encoders/video/video.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * video.h : OBE video encoding headers 3 | ***************************************************************************** 4 | * Copyright (C) 2010 Open Broadcast Systems Ltd. 5 | * 6 | * Authors: Kieran Kunhya 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | *****************************************************************************/ 23 | 24 | #ifndef OBE_ENCODERS_VIDEO_H 25 | #define OBE_ENCODERS_VIDEO_H 26 | 27 | typedef struct 28 | { 29 | void* (*start_encoder)( void *ptr ); 30 | } obe_vid_enc_func_t; 31 | 32 | typedef struct 33 | { 34 | obe_t *h; 35 | obe_encoder_t *encoder; 36 | x264_param_t avc_param; 37 | } obe_vid_enc_params_t; 38 | 39 | extern const obe_vid_enc_func_t x264_encoder; 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /filters/audio/audio.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * audio.h : OBE audio filter headers 3 | ***************************************************************************** 4 | * Copyright (C) 2012 Open Broadcast Systems Ltd. 5 | * 6 | * Authors: Kieran Kunhya 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | *****************************************************************************/ 23 | 24 | #ifndef OBE_FILTERS_AUDIO_H 25 | #define OBE_FILTERS_AUDIO_H 26 | #include 27 | 28 | typedef struct 29 | { 30 | void* (*start_filter)( void *ptr ); 31 | } obe_aud_filter_func_t; 32 | 33 | typedef struct 34 | { 35 | obe_t *h; 36 | obe_filter_t *filter; 37 | } obe_aud_filter_params_t; 38 | 39 | extern const obe_aud_filter_func_t audio_filter; 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /filters/video/video.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * video.h : OBE video filter headers 3 | ***************************************************************************** 4 | * Copyright (C) 2010 Open Broadcast Systems Ltd. 5 | * 6 | * Authors: Kieran Kunhya 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | *****************************************************************************/ 23 | 24 | #ifndef OBE_FILTERS_VIDEO_H 25 | #define OBE_FILTERS_VIDEO_H 26 | 27 | typedef struct 28 | { 29 | void* (*start_filter)( void *ptr ); 30 | } obe_vid_filter_func_t; 31 | 32 | typedef struct 33 | { 34 | obe_t *h; 35 | obe_filter_t *filter; 36 | obe_int_input_stream_t *input_stream; 37 | int target_csp; 38 | } obe_vid_filter_params_t; 39 | 40 | extern const obe_vid_filter_func_t video_filter; 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /common/lavc.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * lavc.h: libavcodec common functions header 3 | ***************************************************************************** 4 | * Copyright (C) 2010 Open Broadcast Systems Ltd. 5 | * 6 | * Authors: Kieran Kunhya 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | *****************************************************************************/ 23 | 24 | #ifndef OBE_INPUT_LAVC_H 25 | #define OBE_INPUT_LAVC_H 26 | 27 | #include 28 | 29 | int obe_get_buffer( AVCodecContext *codec, AVFrame *pic ); 30 | void obe_release_buffer( AVCodecContext *codec, AVFrame *pic ); 31 | int obe_reget_buffer( AVCodecContext *codec, AVFrame *pic ); 32 | int obe_lavc_lockmgr( void **mutex, enum AVLockOp op ); 33 | 34 | #define obe_free_packet( pkt )\ 35 | {\ 36 | av_free_packet( pkt );\ 37 | av_init_packet( pkt );\ 38 | } 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /common/network/udp/udp.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * udp.h : UDP output headers 3 | ***************************************************************************** 4 | * Copyright (C) 2010 Open Broadcast Systems Ltd. 5 | * 6 | * Authors: Kieran Kunhya 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | *****************************************************************************/ 23 | 24 | #ifndef OBE_COMMON_UDP_H 25 | #define OBE_COMMON_UDP_H 26 | 27 | typedef struct obe_udp_opts_t 28 | { 29 | char hostname[1024]; 30 | int port; 31 | int local_port; 32 | int reuse_socket; 33 | int ttl; 34 | int buffer_size; 35 | int miface; 36 | } obe_udp_opts_t; 37 | 38 | void udp_populate_opts( obe_udp_opts_t *udp_opts, char *uri ); 39 | int udp_open( hnd_t *p_handle, obe_udp_opts_t *udp_opts ); 40 | int udp_write( hnd_t p_handle, uint8_t *buf, int size ); 41 | void udp_close( hnd_t handle ); 42 | 43 | #endif /* OBE_COMMON_UDP_H */ 44 | -------------------------------------------------------------------------------- /encoders/audio/audio.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * audio.h : OBE audio encoding headers 3 | ***************************************************************************** 4 | * Copyright (C) 2010 Open Broadcast Systems Ltd. 5 | * 6 | * Authors: Kieran Kunhya 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | *****************************************************************************/ 23 | 24 | #ifndef OBE_ENCODERS_AUDIO_H 25 | #define OBE_ENCODERS_AUDIO_H 26 | 27 | #include 28 | 29 | typedef struct 30 | { 31 | void* (*start_encoder)( void *ptr ); 32 | } obe_aud_enc_func_t; 33 | 34 | typedef struct 35 | { 36 | obe_t *h; 37 | obe_encoder_t *encoder; 38 | obe_output_stream_t *stream; 39 | 40 | int input_sample_format; 41 | int sample_rate; 42 | int frames_per_pes; 43 | } obe_aud_enc_params_t; 44 | 45 | extern const obe_aud_enc_func_t twolame_encoder; 46 | extern const obe_aud_enc_func_t lavc_encoder; 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /filters/audio/337m/337m.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * 337m.c : SMPTE 337M functions 3 | ***************************************************************************** 4 | * Copyright (C) 2010 NAMETBD 5 | * 6 | * Authors: Kieran Kunhya 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | *****************************************************************************/ 23 | 24 | #define 337M_SYNCWORD_1_16_BIT 0xf872 25 | #define 337M_SYNCWORD_1_20_BIT 0x6f872 26 | #define 337M_SYNCWORD_1_24_BIT 0x96f872 27 | 28 | #define 337M_SYNCWORD_2_16_BIT 0x4e1f 29 | #define 337M_SYNCWORD_2_20_BIT 0x54e1f 30 | #define 337M_SYNCWORD_2_24_BIT 0xa54e1f 31 | 32 | #define 337M_DATA_TYPE_NULL 0 33 | #define 337M_DATA_TYPE_AC_3 1 34 | #define 337M_DATA_TYPE_TIMESTAMP 2 35 | #define 337M_DATA_TYPE_MP2 6 36 | #define 337M_DATA_TYPE_AAC 10 37 | #define 337M_DATA_TYPE_HE_AAC 11 38 | #define 337M_DATA_TYPE_E_AC_3 16 39 | #define 337M_DATA_TYPE_E_DIST 28 40 | 41 | // 337M startcode search function TODO 42 | -------------------------------------------------------------------------------- /input/input.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * input.h : OBE input headers 3 | ***************************************************************************** 4 | * Copyright (C) 2010 Open Broadcast Systems Ltd. 5 | * 6 | * Authors: Kieran Kunhya 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | *****************************************************************************/ 23 | 24 | #ifndef OBE_INPUT_H 25 | #define OBE_INPUT_H 26 | 27 | typedef struct 28 | { 29 | void* (*probe_input)( void *ptr ); 30 | void* (*open_input)( void *ptr ); 31 | } obe_input_func_t; 32 | 33 | typedef struct 34 | { 35 | obe_t *h; 36 | obe_input_t user_opts; 37 | } obe_input_probe_t; 38 | 39 | typedef struct 40 | { 41 | obe_t *h; 42 | obe_device_t *device; 43 | int num_output_streams; 44 | obe_output_stream_t *output_streams; 45 | int audio_samples; 46 | } obe_input_params_t; 47 | 48 | //extern const obe_input_func_t lavf_input; 49 | #if HAVE_DECKLINK 50 | extern const obe_input_func_t decklink_input; 51 | #endif 52 | extern const obe_input_func_t linsys_sdi_input; 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /input/sdi/decklink/include/DeckLinkAPIVersion.h: -------------------------------------------------------------------------------- 1 | /* -LICENSE-START- 2 | * ** Copyright (c) 2013 Blackmagic Design 3 | * ** 4 | * ** Permission is hereby granted, free of charge, to any person or organization 5 | * ** obtaining a copy of the software and accompanying documentation covered by 6 | * ** this license (the "Software") to use, reproduce, display, distribute, 7 | * ** execute, and transmit the Software, and to prepare derivative works of the 8 | * ** Software, and to permit third-parties to whom the Software is furnished to 9 | * ** do so, all subject to the following: 10 | * ** 11 | * ** The copyright notices in the Software and this entire statement, including 12 | * ** the above license grant, this restriction and the following disclaimer, 13 | * ** must be included in all copies of the Software, in whole or in part, and 14 | * ** all derivative works of the Software, unless such copies or derivative 15 | * ** works are solely in the form of machine-executable object code generated by 16 | * ** a source language processor. 17 | * ** 18 | * ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * ** FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 21 | * ** SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 22 | * ** FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 23 | * ** ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 24 | * ** DEALINGS IN THE SOFTWARE. 25 | * ** -LICENSE-END- 26 | * */ 27 | 28 | /* DeckLinkAPIVersion.h */ 29 | 30 | #ifndef __DeckLink_API_Verison_h__ 31 | #define __DeckLink_API_Version_h__ 32 | 33 | #define BLACKMAGIC_DECKLINK_API_VERSION 0x09070100 34 | #define BLACKMAGIC_DECKLINK_API_VERSION_STRING "9.7.1" 35 | 36 | #endif // __DeckLink_API_Version_h__ 37 | 38 | -------------------------------------------------------------------------------- /input/sdi/x86/sdi.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * sdi.h: sdi asm prototypes 3 | ***************************************************************************** 4 | * Copyright (C) 2010 Open Broadcast Systems Ltd. 5 | * 6 | * Authors: Kieran Kunhya 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | *****************************************************************************/ 23 | 24 | #ifndef OBE_X86_SDI 25 | #define OBE_X86_SDI 26 | 27 | void obe_downscale_line_mmx( uint16_t *src, uint8_t *dst, int lines ); 28 | void obe_downscale_line_sse2( uint16_t *src, uint8_t *dst, int lines ); 29 | 30 | void obe_v210_planar_unpack_c( const uint32_t *src, uint16_t *y, uint16_t *u, uint16_t *v, int width ); 31 | 32 | void obe_v210_planar_unpack_unaligned_ssse3( const uint32_t *src, uint16_t *y, uint16_t *u, uint16_t *v, int width ); 33 | void obe_v210_planar_unpack_unaligned_avx( const uint32_t *src, uint16_t *y, uint16_t *u, uint16_t *v, int width ); 34 | 35 | void obe_v210_planar_unpack_aligned_ssse3( const uint32_t *src, uint16_t *y, uint16_t *u, uint16_t *v, int width ); 36 | void obe_v210_planar_unpack_aligned_avx( const uint32_t *src, uint16_t *y, uint16_t *u, uint16_t *v, int width ); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /input/sdi/x86/sdi.asm: -------------------------------------------------------------------------------- 1 | %include "x86util.asm" 2 | 3 | SECTION_RODATA 4 | 5 | v210_mask: times 4 dd 0x3ff 6 | v210_mult: dw 64,4,64,4,64,4,64,4 7 | v210_luma_shuf: db 8,9,0,1,2,3,12,13,4,5,6,7,-1,-1,-1,-1 8 | v210_chroma_shuf: db 0,1,8,9,6,7,-1,-1,2,3,4,5,12,13,-1,-1 9 | 10 | SECTION .text 11 | 12 | ; downscale_line( uint16_t *src, uint8_t *dst, int lines ); 13 | 14 | %macro DOWNSCALE_line 0 15 | 16 | cglobal downscale_line, 3,3,2 17 | imul r2d, 1440 18 | .loop 19 | mova m0, [r0] 20 | mova m1, [r0+mmsize] 21 | psrlw m0, 2 22 | psrlw m1, 2 23 | packuswb m0, m1 24 | mova [r1], m0 25 | 26 | lea r0, [r0+2*mmsize] 27 | lea r1, [r1+mmsize] 28 | sub r2d, mmsize 29 | jg .loop 30 | REP_RET 31 | %endmacro 32 | 33 | INIT_MMX mmx 34 | DOWNSCALE_line 35 | INIT_XMM sse2 36 | DOWNSCALE_line 37 | 38 | %macro v210_planar_unpack 1 39 | 40 | ; v210_planar_unpack(const uint32_t *src, uint16_t *y, uint16_t *u, uint16_t *v, int width) 41 | cglobal v210_planar_unpack_%1, 5, 5, 7 42 | movsxdifnidn r4, r4d 43 | lea r1, [r1+2*r4] 44 | add r2, r4 45 | add r3, r4 46 | neg r4 47 | 48 | mova m3, [v210_mult] 49 | mova m4, [v210_mask] 50 | mova m5, [v210_luma_shuf] 51 | mova m6, [v210_chroma_shuf] 52 | .loop 53 | %ifidn %1, unaligned 54 | movu m0, [r0] 55 | %else 56 | mova m0, [r0] 57 | %endif 58 | 59 | pmullw m1, m0, m3 60 | psrld m0, 10 61 | psrlw m1, 6 ; u0 v0 y1 y2 v1 u2 y4 y5 62 | pand m0, m4 ; y0 __ u1 __ y3 __ v2 __ 63 | 64 | shufps m2, m1, m0, 0x8d ; y1 y2 y4 y5 y0 __ y3 __ 65 | pshufb m2, m5 ; y0 y1 y2 y3 y4 y5 __ __ 66 | movu [r1+2*r4], m2 67 | 68 | shufps m1, m0, 0xd8 ; u0 v0 v1 u2 u1 __ v2 __ 69 | pshufb m1, m6 ; u0 u1 u2 __ v0 v1 v2 __ 70 | movq [r2+r4], m1 71 | movhps [r3+r4], m1 72 | 73 | add r0, mmsize 74 | add r4, 6 75 | jl .loop 76 | 77 | REP_RET 78 | %endmacro 79 | 80 | INIT_XMM ssse3 81 | v210_planar_unpack unaligned 82 | INIT_XMM avx 83 | v210_planar_unpack unaligned 84 | 85 | INIT_XMM ssse3 86 | v210_planar_unpack aligned 87 | INIT_XMM avx 88 | v210_planar_unpack aligned 89 | -------------------------------------------------------------------------------- /filters/video/x86/vfilter.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * vfilter.h: video filter asm prototypes 3 | ***************************************************************************** 4 | * Copyright (C) 2010 Open Broadcast Systems Ltd. 5 | * 6 | * Authors: Kieran Kunhya 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | *****************************************************************************/ 23 | 24 | #ifndef OBE_X86_VFILTER 25 | #define OBE_X86_VFILTER 26 | 27 | void obe_scale_plane_mmxext( uint16_t *src, int stride, int width, int height, int lshift, int rshift ); 28 | void obe_scale_plane_sse2( uint16_t *src, int stride, int width, int height, int lshift, int rshift ); 29 | void obe_scale_plane_avx( uint16_t *src, int stride, int width, int height, int lshift, int rshift ); 30 | 31 | void obe_downsample_chroma_row_top_sse2( uint16_t *src, uint16_t *dst, int width, int stride ); 32 | void obe_downsample_chroma_row_bottom_sse2( uint16_t *src, uint16_t *dst, int width, int stride ); 33 | void obe_downsample_chroma_row_top_avx( uint16_t *src, uint16_t *dst, int width, int stride ); 34 | void obe_downsample_chroma_row_bottom_avx( uint16_t *src, uint16_t *dst, int width, int stride ); 35 | 36 | void obe_dither_row_10_to_8_sse4( uint16_t *src, uint8_t *dst, const uint16_t *dither, int width, int stride ); 37 | void obe_dither_row_10_to_8_avx( uint16_t *src, uint8_t *dst, const uint16_t *dither, int width, int stride ); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /common/network/network.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * network.h : Networking headers 3 | ***************************************************************************** 4 | * Copyright (C) 2010 FFmpeg 5 | * 6 | * Authors: Kieran Kunhya 7 | * 8 | * This code originates from FFmpeg. 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 22 | * 23 | *****************************************************************************/ 24 | 25 | #ifndef OUTPUT_NETWORK_H 26 | #define OUTPUT_NETWORK_H 27 | 28 | #include "common/common.h" 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #ifndef IN_MULTICAST 39 | #define IN_MULTICAST(a) ((((uint32_t)(a)) & 0xf0000000) == 0xe0000000) 40 | #endif 41 | #ifndef IN6_IS_ADDR_MULTICAST 42 | #define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *) (a))[0] == 0xff) 43 | #endif 44 | 45 | static inline int is_multicast_address( struct sockaddr *addr ) 46 | { 47 | if( addr->sa_family == AF_INET ) 48 | { 49 | return IN_MULTICAST( ntohl( ((struct sockaddr_in *)addr)->sin_addr.s_addr ) ); 50 | } 51 | #if HAVE_STRUCT_SOCKADDR_IN6 52 | if( addr->sa_family == AF_INET6 ) 53 | { 54 | return IN6_IS_ADDR_MULTICAST( &((struct sockaddr_in6 *)addr)->sin6_addr ); 55 | } 56 | #endif 57 | 58 | return 0; 59 | } 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /filters/video/x86/vfilter.asm: -------------------------------------------------------------------------------- 1 | %include "x86util.asm" 2 | 3 | SECTION .rodata 4 | 5 | align 32 6 | scale: times 4 dd 511 7 | shift: dd 11 8 | 9 | align 32 10 | two: times 8 dw 2 11 | three: times 8 dw 3 12 | 13 | SECTION .text 14 | 15 | ; 16 | ; obe_dither_row_10_to_8( uint16_t *src, uint8_t *dst, const uint16_t *dithers, int width, int stride ) 17 | ; 18 | 19 | %macro DITHER_row 0 20 | 21 | cglobal dither_row_10_to_8, 5, 5, 8 22 | mova m2, [r2] 23 | mova m5, [scale] 24 | movd m6, [shift] 25 | pxor m7, m7 26 | lea r0, [r0+2*r3] 27 | add r1, r3 28 | neg r3 29 | 30 | .loop 31 | paddw m0, m2, [r0+2*r3] 32 | paddw m1, m2, [r0+2*r3+16] 33 | 34 | punpcklwd m3, m0, m7 35 | punpcklwd m4, m1, m7 36 | punpckhwd m0, m7 37 | punpckhwd m1, m7 38 | pmulld m3, m5 39 | pmulld m4, m5 40 | pmulld m0, m5 41 | pmulld m1, m5 42 | psrld m3, m6 43 | psrld m4, m6 44 | psrld m0, m6 45 | psrld m1, m6 46 | packusdw m3, m0 47 | packusdw m4, m1 48 | 49 | packuswb m3, m4 50 | mova [r1+r3], m3 51 | 52 | add r3, mmsize 53 | jl .loop 54 | REP_RET 55 | %endmacro 56 | 57 | INIT_XMM sse4 58 | DITHER_row 59 | INIT_XMM avx 60 | DITHER_row 61 | 62 | ; 63 | ; obe_downsample_chroma_row_field( uint16_t *src, uint16_t *dst, int width, int stride ) 64 | ; 65 | 66 | ; %1 * 3 67 | ; %2 + 2 68 | %macro DOWNSAMPLE_chroma_row_inner 2 69 | pmullw m2, m0, [%1+r2] 70 | paddw m3, m1, [%2+r2] 71 | paddw m2, m3 72 | psrlw m2, 2 73 | %endmacro 74 | 75 | %macro DOWNSAMPLE_chroma_row 1 76 | cglobal downsample_chroma_row_%1, 4, 5, 4 77 | mova m0, [three] 78 | mova m1, [two] 79 | add r0, r2 80 | add r1, r2 81 | lea r4, [r0+2*r3] 82 | neg r2 83 | .loop 84 | 85 | %ifidn %1, top 86 | DOWNSAMPLE_chroma_row_inner r0, r4 87 | %else 88 | DOWNSAMPLE_chroma_row_inner r4, r0 89 | %endif 90 | 91 | mova [r1+r2], m2 92 | 93 | add r2, mmsize 94 | jl .loop 95 | REP_RET 96 | %endmacro 97 | 98 | INIT_XMM sse2 99 | DOWNSAMPLE_chroma_row top 100 | DOWNSAMPLE_chroma_row bottom 101 | 102 | INIT_XMM avx 103 | DOWNSAMPLE_chroma_row top 104 | DOWNSAMPLE_chroma_row bottom 105 | -------------------------------------------------------------------------------- /input/sdi/ancillary.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * ancillary.h : OBE ancillary headers 3 | ***************************************************************************** 4 | * Copyright (C) 2010 Open Broadcast Systems Ltd. 5 | * 6 | * Authors: Kieran Kunhya 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | *****************************************************************************/ 23 | 24 | #ifndef OBE_ANCILLARY_H 25 | #define OBE_ANCILLARY_H 26 | 27 | #include "common/common.h" 28 | #include "sdi.h" 29 | 30 | typedef struct 31 | { 32 | uint8_t did; 33 | uint8_t sdid; 34 | int type; 35 | } obe_anc_identifier_t; 36 | 37 | const static obe_anc_identifier_t vanc_identifiers[] = 38 | { 39 | /* SMPTE 2016 */ 40 | { 0x41, 0x05, MISC_AFD }, /* Includes Bar-Data */ 41 | { 0x41, 0x06, MISC_PAN_SCAN }, 42 | 43 | /* SMPTE 2010 */ 44 | { 0x41, 0x07, VANC_SCTE_104 }, 45 | 46 | /* SMPTE 2031 */ 47 | { 0x41, 0x08, VANC_DVB_SCTE_VBI }, 48 | 49 | /* OP-47 / SMPTE RDD-8 */ 50 | { 0x43, 0x01, VANC_OP47_SDP }, 51 | { 0x43, 0x02, VANC_OP47_MULTI_PACKET }, 52 | 53 | /* SMPTE 12M */ 54 | { 0x60, 0x60, VANC_ATC }, 55 | 56 | /* SMPTE 334 */ 57 | { 0x61, 0x01, CAPTIONS_CEA_708 }, 58 | { 0x61, 0x02, CAPTIONS_CEA_608 }, 59 | 60 | /* SMPTE RP-207 */ 61 | { 0x62, 0x01, VANC_DTV_PROGRAM_DESCRIPTION }, 62 | 63 | { 0x62, 0x02, VANC_DTV_DATA_BROADCAST }, 64 | 65 | /* SMPTE RP-208 (legacy) */ 66 | { 0x62, 0x03, VANC_SMPTE_VBI }, 67 | 68 | { 0, 0, 0 }, 69 | }; 70 | 71 | 72 | int parse_vanc_line( obe_t *h, obe_sdi_non_display_data_t *non_display_data, obe_raw_frame_t *raw_frame, 73 | uint16_t *line, int width, int line_number ); 74 | #endif 75 | -------------------------------------------------------------------------------- /common/linsys/util.h: -------------------------------------------------------------------------------- 1 | /* util.h 2 | * 3 | * Header file for Master Linux SDK example program utility functions. 4 | * 5 | * Copyright (C) 2004-2005 Linear Systems Ltd. All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of Linear Systems Ltd. nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY LINEAR SYSTEMS LTD. "AS IS" AND ANY 22 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL LINEAR SYSTEMS LTD. OR CONTRIBUTORS 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 26 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 28 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 31 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | * Linear Systems can be contacted at . 34 | * 35 | */ 36 | 37 | #ifndef _UTIL_H 38 | #define _UTIL_H 39 | 40 | #include 41 | 42 | #define UTIL_ASIRX 0x1 43 | #define UTIL_ASITX 0x2 44 | #define UTIL_SDIRX 0x4 45 | #define UTIL_SDITX 0x8 46 | 47 | struct util_info { 48 | unsigned int id; 49 | const char *name; 50 | unsigned int flags; 51 | }; 52 | 53 | /* External function prototypes */ 54 | ssize_t util_read (const char *name, char *buf, size_t count); 55 | ssize_t util_write (const char *name, const char *buf, size_t count); 56 | ssize_t util_strtoul (const char *name, unsigned long int *val); 57 | ssize_t util_strtoull (const char *name, unsigned long long int *val); 58 | void fprinttime (FILE *stream, const char *progname); 59 | struct util_info *getinfo (unsigned int id); 60 | 61 | #endif 62 | 63 | -------------------------------------------------------------------------------- /input/sdi/decklink/include/DeckLinkAPIDiscovery.h: -------------------------------------------------------------------------------- 1 | /* -LICENSE-START- 2 | ** Copyright (c) 2013 Blackmagic Design 3 | ** 4 | ** Permission is hereby granted, free of charge, to any person or organization 5 | ** obtaining a copy of the software and accompanying documentation covered by 6 | ** this license (the "Software") to use, reproduce, display, distribute, 7 | ** execute, and transmit the Software, and to prepare derivative works of the 8 | ** Software, and to permit third-parties to whom the Software is furnished to 9 | ** do so, all subject to the following: 10 | ** 11 | ** The copyright notices in the Software and this entire statement, including 12 | ** the above license grant, this restriction and the following disclaimer, 13 | ** must be included in all copies of the Software, in whole or in part, and 14 | ** all derivative works of the Software, unless such copies or derivative 15 | ** works are solely in the form of machine-executable object code generated by 16 | ** a source language processor. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | ** FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 21 | ** SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 22 | ** FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 23 | ** ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 24 | ** DEALINGS IN THE SOFTWARE. 25 | ** -LICENSE-END- 26 | */ 27 | 28 | #ifndef BMD_DECKLINKAPIDISCOVERY_H 29 | #define BMD_DECKLINKAPIDISCOVERY_H 30 | 31 | 32 | #ifndef BMD_CONST 33 | #if defined(_MSC_VER) 34 | #define BMD_CONST __declspec(selectany) static const 35 | #else 36 | #define BMD_CONST static const 37 | #endif 38 | #endif 39 | 40 | // Type Declarations 41 | 42 | 43 | // Interface ID Declarations 44 | 45 | BMD_CONST REFIID IID_IDeckLink = /* C418FBDD-0587-48ED-8FE5-640F0A14AF91 */ {0xC4,0x18,0xFB,0xDD,0x05,0x87,0x48,0xED,0x8F,0xE5,0x64,0x0F,0x0A,0x14,0xAF,0x91}; 46 | 47 | // Forward Declarations 48 | 49 | class IDeckLink; 50 | 51 | /* Interface IDeckLink - represents a DeckLink device */ 52 | 53 | class IDeckLink : public IUnknown 54 | { 55 | public: 56 | virtual HRESULT GetModelName (/* out */ const char **modelName) = 0; 57 | virtual HRESULT GetDisplayName (/* out */ const char **displayName) = 0; 58 | 59 | protected: 60 | virtual ~IDeckLink () {}; // call Release method to drop reference count 61 | }; 62 | 63 | /* Functions */ 64 | 65 | extern "C" { 66 | 67 | 68 | }; 69 | 70 | 71 | #endif /* defined(BMD_DECKLINKAPIDISCOVERY_H) */ 72 | -------------------------------------------------------------------------------- /common/linsys/master.h: -------------------------------------------------------------------------------- 1 | /* master.h 2 | * 3 | * Global definitions for Linear Systems Ltd. 4 | * digital television-related boards. 5 | * 6 | * Copyright (C) 2004-2010 Linear Systems Ltd. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * 1. Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Linear Systems Ltd. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY LINEAR SYSTEMS LTD. "AS IS" AND ANY 23 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL LINEAR SYSTEMS LTD. OR CONTRIBUTORS 26 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 27 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 29 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 31 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 32 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Linear Systems can be contacted at . 35 | * 36 | */ 37 | 38 | #ifndef _MASTER_H 39 | #define _MASTER_H 40 | 41 | #define MASTER_DRIVER_VERSION "2.7.2" 42 | #define MASTER_DRIVER_VERSION_CODE 0x020702 43 | #define MASTER_DRIVER_DATE "2010-12-17" 44 | 45 | #define MASTER_PCI_VENDOR_ID_LINSYS 0x1254 46 | 47 | /* Device capabilities */ 48 | #define MASTER_CAP_BYPASS 0x00000001 49 | #define MASTER_CAP_WATCHDOG 0x00000002 50 | #define MASTER_CAP_GPI 0x00000004 51 | #define MASTER_CAP_GPO 0x00000008 52 | #define MASTER_CAP_UID 0x00000010 53 | #define MASTER_CAP_BLACKBURST 0x00000020 54 | 55 | /* Bypass mode settings */ 56 | #define MASTER_CTL_BYPASS_ENABLE 0 57 | #define MASTER_CTL_BYPASS_DISABLE 1 58 | #define MASTER_CTL_BYPASS_WATCHDOG 2 59 | 60 | /* Black burst type settings */ 61 | #define MASTER_CTL_BLACKBURST_NTSC 0 62 | #define MASTER_CTL_BLACKBURST_PAL 1 63 | 64 | /* Maximum watchdog timeout in milliseconds. 65 | * Limited to 32 bits at 40 MHz or 27 MHz */ 66 | #define MASTER_WATCHDOG_MAX 100000 67 | 68 | #endif 69 | 70 | -------------------------------------------------------------------------------- /common/lavc.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * lavc.c: libavcodec common functions 3 | ***************************************************************************** 4 | * Copyright (C) 2010 Open Broadcast Systems Ltd. 5 | * 6 | * Authors: Kieran Kunhya 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | *****************************************************************************/ 23 | 24 | #include "common/common.h" 25 | #include 26 | 27 | int obe_get_buffer( AVCodecContext *codec, AVFrame *pic ) 28 | { 29 | int w = codec->width; 30 | int h = codec->height; 31 | int stride[4]; 32 | 33 | avcodec_align_dimensions2( codec, &w, &h, stride ); 34 | 35 | /* Only EDGE_EMU codecs are used 36 | * Allocate an extra line so that SIMD can modify the entire stride for every active line */ 37 | if( av_image_alloc( pic->data, pic->linesize, w, h + 1, codec->pix_fmt, 32 ) < 0 ) 38 | return -1; 39 | 40 | pic->reordered_opaque = codec->reordered_opaque; 41 | pic->pkt_pts = codec->pkt ? codec->pkt->pts : AV_NOPTS_VALUE; 42 | 43 | return 0; 44 | } 45 | 46 | void obe_release_buffer( AVCodecContext *codec, AVFrame *pic ) 47 | { 48 | /* FIXME: need to release frame when both decoder and encoder are done */ 49 | //av_freep( &pic->data[0] ); 50 | memset( pic->data, 0, sizeof(pic->data) ); 51 | } 52 | 53 | /* FFmpeg shouldn't call this at the moment */ 54 | int obe_reget_buffer( AVCodecContext *codec, AVFrame *pic ) 55 | { 56 | if( pic->data[0] == NULL ) 57 | return codec->get_buffer( codec, pic ); 58 | 59 | pic->reordered_opaque = codec->reordered_opaque; 60 | pic->pkt_pts = codec->pkt ? codec->pkt->pts : AV_NOPTS_VALUE; 61 | 62 | return 0; 63 | } 64 | 65 | int obe_lavc_lockmgr( void **mutex, enum AVLockOp op ) 66 | { 67 | if( op == AV_LOCK_CREATE ) 68 | { 69 | *mutex = malloc( sizeof(pthread_mutex_t) ); 70 | if( !*mutex ) 71 | return -1; 72 | 73 | pthread_mutex_init( *mutex, NULL ); 74 | } 75 | else if( op == AV_LOCK_OBTAIN ) 76 | pthread_mutex_lock( *mutex ); 77 | else if( op == AV_LOCK_RELEASE ) 78 | pthread_mutex_unlock( *mutex ); 79 | else /* AV_LOCK_DESTROY */ 80 | { 81 | pthread_mutex_destroy( *mutex ); 82 | free( *mutex ); 83 | } 84 | 85 | return 0; 86 | } 87 | -------------------------------------------------------------------------------- /input/sdi/vbi.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * vbi.h: OBE VBI parsing functions 3 | ***************************************************************************** 4 | * Copyright (C) 2010 Open Broadcast Systems Ltd. 5 | * 6 | * Authors: Kieran Kunhya 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | *****************************************************************************/ 23 | 24 | #ifndef OBE_VBI_H 25 | #define OBE_VBI_H 26 | 27 | #define NUM_ACTIVE_VBI_LINES 2 28 | 29 | #define PAL_VIDEO_INDEX_LINE 11 30 | #define NTSC_VIDEO_INDEX_LINE 14 31 | // TODO: Video index field 2 32 | 33 | enum dvb_vbi_data_unit_id_e 34 | { 35 | DATA_UNIT_ID_EBU_TTX_NON_SUB = 0x02, 36 | DATA_UNIT_ID_EBU_TTX_SUB, 37 | DATA_UNIT_ID_TTX_INVERTED = 0xc0, 38 | DATA_UNIT_ID_VPS = 0xc3, 39 | DATA_UNIT_ID_WSS, 40 | DATA_UNIT_ID_CEA_608, 41 | DATA_UNIT_ID_AMOL_48 = 0xd0, 42 | DATA_UNIT_ID_AMOL_96, 43 | DATA_UNIT_ID_NABTS = 0xd5, 44 | DATA_UNIT_ID_TVG2X, 45 | DATA_UNIT_ID_CP, 46 | DATA_UNIT_ID_VITC = 0xd9, 47 | }; 48 | 49 | /* Convert DVB/SCTE data indentifier to OBE internal format */ 50 | const static int data_indentifier_table[][2] = 51 | { 52 | { DATA_UNIT_ID_EBU_TTX_NON_SUB, MISC_TELETEXT }, 53 | { DATA_UNIT_ID_EBU_TTX_SUB, MISC_TELETEXT }, 54 | { DATA_UNIT_ID_TTX_INVERTED, MISC_TELETEXT_INVERTED }, 55 | { DATA_UNIT_ID_VPS, MISC_VPS }, 56 | { DATA_UNIT_ID_WSS, MISC_WSS }, 57 | { DATA_UNIT_ID_CEA_608, CAPTIONS_CEA_608 }, 58 | { DATA_UNIT_ID_AMOL_48, VBI_AMOL_48 }, 59 | { DATA_UNIT_ID_AMOL_96, VBI_AMOL_96 }, 60 | { DATA_UNIT_ID_NABTS, VBI_NABTS }, 61 | { DATA_UNIT_ID_TVG2X, VBI_TVG2X }, 62 | { DATA_UNIT_ID_CP, VBI_CP }, 63 | { DATA_UNIT_ID_VITC, VBI_VITC }, 64 | { -1, -1 }, 65 | }; 66 | 67 | int setup_vbi_parser( obe_sdi_non_display_data_t *non_display_data ); 68 | int decode_vbi( obe_t *h, obe_sdi_non_display_data_t *non_display_data, uint8_t *lines, obe_raw_frame_t *raw_frame ); 69 | int decode_video_index_information( obe_t *h, obe_sdi_non_display_data_t *non_display_data, uint16_t *line, obe_raw_frame_t *raw_frame, int line_number ); 70 | int send_vbi_and_ttx( obe_t *h, obe_sdi_non_display_data_t *non_display_parser, int64_t pts ); 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /filters/video/dither.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * dither.h : OBE video dithering tables 3 | ***************************************************************************** 4 | * Copyright (C) 2010 FFmpeg project 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 19 | * 20 | *****************************************************************************/ 21 | 22 | #ifndef OBE_FILTERS_DITHER_H 23 | #define OBE_FILTERS_DITHER_H 24 | 25 | DECLARE_ALIGNED(16, const uint16_t, obe_dithers)[8][8] = 26 | { 27 | { 1, 2, 1, 2, 1, 2, 1, 2 }, 28 | { 3, 0, 3, 0, 3, 0, 3, 0 }, 29 | { 1, 2, 1, 2, 1, 2, 1, 2 }, 30 | { 3, 0, 3, 0, 3, 0, 3, 0 }, 31 | { 1, 2, 1, 2, 1, 2, 1, 2 }, 32 | { 3, 0, 3, 0, 3, 0, 3, 0 }, 33 | { 1, 2, 1, 2, 1, 2, 1, 2 }, 34 | { 3, 0, 3, 0, 3, 0, 3, 0 }, 35 | }; 36 | 37 | uint16_t obe_dither_scale[15][16] = 38 | { 39 | { 2, 3, 3, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,}, 40 | { 2, 3, 7, 7, 13, 13, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,}, 41 | { 3, 3, 4, 15, 15, 29, 57, 57, 57, 113, 113, 113, 113, 113, 113, 113,}, 42 | { 3, 4, 4, 5, 31, 31, 61, 121, 241, 241, 241, 241, 481, 481, 481, 481,}, 43 | { 3, 4, 5, 5, 6, 63, 63, 125, 249, 497, 993, 993, 993, 993, 993, 1985,}, 44 | { 3, 5, 6, 6, 6, 7, 127, 127, 253, 505, 1009, 2017, 4033, 4033, 4033, 4033,}, 45 | { 3, 5, 6, 7, 7, 7, 8, 255, 255, 509, 1017, 2033, 4065, 8129,16257,16257,}, 46 | { 3, 5, 6, 8, 8, 8, 8, 9, 511, 511, 1021, 2041, 4081, 8161,16321,32641,}, 47 | { 3, 5, 7, 8, 9, 9, 9, 9, 10, 1023, 1023, 2045, 4089, 8177,16353,32705,}, 48 | { 3, 5, 7, 8, 10, 10, 10, 10, 10, 11, 2047, 2047, 4093, 8185,16369,32737,}, 49 | { 3, 5, 7, 8, 10, 11, 11, 11, 11, 11, 12, 4095, 4095, 8189,16377,32753,}, 50 | { 3, 5, 7, 9, 10, 12, 12, 12, 12, 12, 12, 13, 8191, 8191,16381,32761,}, 51 | { 3, 5, 7, 9, 10, 12, 13, 13, 13, 13, 13, 13, 14,16383,16383,32765,}, 52 | { 3, 5, 7, 9, 10, 12, 14, 14, 14, 14, 14, 14, 14, 15,32767,32767,}, 53 | { 3, 5, 7, 9, 11, 12, 14, 15, 15, 15, 15, 15, 15, 15, 16,65535,}, 54 | }; 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /input/sdi/decklink/include/LinuxCOM.h: -------------------------------------------------------------------------------- 1 | /* -LICENSE-START- 2 | ** Copyright (c) 2009 Blackmagic Design 3 | ** 4 | ** Permission is hereby granted, free of charge, to any person or organization 5 | ** obtaining a copy of the software and accompanying documentation covered by 6 | ** this license (the "Software") to use, reproduce, display, distribute, 7 | ** execute, and transmit the Software, and to prepare derivative works of the 8 | ** Software, and to permit third-parties to whom the Software is furnished to 9 | ** do so, all subject to the following: 10 | ** 11 | ** The copyright notices in the Software and this entire statement, including 12 | ** the above license grant, this restriction and the following disclaimer, 13 | ** must be included in all copies of the Software, in whole or in part, and 14 | ** all derivative works of the Software, unless such copies or derivative 15 | ** works are solely in the form of machine-executable object code generated by 16 | ** a source language processor. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | ** FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 21 | ** SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 22 | ** FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 23 | ** ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 24 | ** DEALINGS IN THE SOFTWARE. 25 | ** -LICENSE-END- 26 | */ 27 | 28 | #ifndef __LINUX_COM_H_ 29 | #define __LINUX_COM_H_ 30 | 31 | struct REFIID 32 | { 33 | unsigned char byte0; 34 | unsigned char byte1; 35 | unsigned char byte2; 36 | unsigned char byte3; 37 | unsigned char byte4; 38 | unsigned char byte5; 39 | unsigned char byte6; 40 | unsigned char byte7; 41 | unsigned char byte8; 42 | unsigned char byte9; 43 | unsigned char byte10; 44 | unsigned char byte11; 45 | unsigned char byte12; 46 | unsigned char byte13; 47 | unsigned char byte14; 48 | unsigned char byte15; 49 | }; 50 | 51 | typedef REFIID CFUUIDBytes; 52 | #define CFUUIDGetUUIDBytes(x) x 53 | 54 | typedef int HRESULT; 55 | typedef unsigned long ULONG; 56 | typedef void *LPVOID; 57 | 58 | #define SUCCEEDED(Status) ((HRESULT)(Status) >= 0) 59 | #define FAILED(Status) ((HRESULT)(Status)<0) 60 | 61 | #define IS_ERROR(Status) ((unsigned long)(Status) >> 31 == SEVERITY_ERROR) 62 | #define HRESULT_CODE(hr) ((hr) & 0xFFFF) 63 | #define HRESULT_FACILITY(hr) (((hr) >> 16) & 0x1fff) 64 | #define HRESULT_SEVERITY(hr) (((hr) >> 31) & 0x1) 65 | #define SEVERITY_SUCCESS 0 66 | #define SEVERITY_ERROR 1 67 | 68 | #define MAKE_HRESULT(sev,fac,code) ((HRESULT) (((unsigned long)(sev)<<31) | ((unsigned long)(fac)<<16) | ((unsigned long)(code))) ) 69 | 70 | #define S_OK ((HRESULT)0x00000000L) 71 | #define S_FALSE ((HRESULT)0x00000001L) 72 | #define E_UNEXPECTED ((HRESULT)0x8000FFFFL) 73 | #define E_NOTIMPL ((HRESULT)0x80000001L) 74 | #define E_OUTOFMEMORY ((HRESULT)0x80000002L) 75 | #define E_INVALIDARG ((HRESULT)0x80000003L) 76 | #define E_NOINTERFACE ((HRESULT)0x80000004L) 77 | #define E_POINTER ((HRESULT)0x80000005L) 78 | #define E_HANDLE ((HRESULT)0x80000006L) 79 | #define E_ABORT ((HRESULT)0x80000007L) 80 | #define E_FAIL ((HRESULT)0x80000008L) 81 | #define E_ACCESSDENIED ((HRESULT)0x80000009L) 82 | 83 | #define STDMETHODCALLTYPE 84 | 85 | #define IID_IUnknown (REFIID){0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46} 86 | #define IUnknownUUID IID_IUnknown 87 | 88 | #ifdef __cplusplus 89 | class IUnknown 90 | { 91 | public: 92 | virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, LPVOID *ppv) = 0; 93 | virtual ULONG STDMETHODCALLTYPE AddRef(void) = 0; 94 | virtual ULONG STDMETHODCALLTYPE Release(void) = 0; 95 | }; 96 | #endif 97 | 98 | #endif 99 | 100 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Makefile 2 | 3 | include config.mak 4 | 5 | all: default 6 | 7 | SRCS = obe.c common/lavc.c common/network/udp/udp.c \ 8 | common/linsys/util.c \ 9 | input/sdi/sdi.c input/sdi/ancillary.c input/sdi/vbi.c input/sdi/linsys/linsys.c \ 10 | filters/video/video.c filters/video/cc.c filters/audio/audio.c \ 11 | encoders/smoothing.c encoders/audio/lavc/lavc.c encoders/video/avc/x264.c \ 12 | mux/smoothing.c mux/ts/ts.c \ 13 | output/ip/ip.c 14 | 15 | SRCCXX = 16 | 17 | SRCCLI = obecli.c 18 | 19 | SRCSO = 20 | 21 | CONFIG := $(shell cat config.h) 22 | 23 | # Optional module sources 24 | ifneq ($(findstring HAVE_LIBTWOLAME 1, $(CONFIG)),) 25 | SRCS += encoders/audio/mp2/twolame.c 26 | endif 27 | 28 | ifneq ($(findstring HAVE_DECKLINK 1, $(CONFIG)),) 29 | SRCCXX += input/sdi/decklink/decklink.cpp 30 | endif 31 | 32 | # MMX/SSE optims 33 | ifneq ($(AS),) 34 | X86SRC0 = vfilter.asm 35 | X86SRC = $(X86SRC0:%=filters/video/x86/%) 36 | X86SRC1 = sdi.asm 37 | X86SRC += $(X86SRC1:%=input/sdi/x86/%) 38 | 39 | 40 | ifeq ($(ARCH),X86_64) 41 | ARCH_X86 = yes 42 | ASMSRC = $(X86SRC:-32.asm=-64.asm) 43 | ASFLAGS += -DARCH_X86_64=1 -DHAVE_CPUNOP=1 44 | endif 45 | 46 | ifdef ARCH_X86 47 | ASFLAGS += -I$(SRCPATH)/common/x86/ 48 | OBJASM = $(ASMSRC:%.asm=%.o) 49 | $(OBJASM): common/x86/x86inc.asm common/x86/x86util.asm 50 | endif 51 | endif 52 | 53 | OBJS = $(SRCS:%.c=%.o) 54 | OBJSCXX = $(SRCCXX:%.cpp=%.o) 55 | OBJCLI = $(SRCCLI:%.c=%.o) 56 | OBJSO = $(SRCSO:%.c=%.o) 57 | DEP = depend 58 | 59 | .PHONY: all default fprofiled clean distclean install uninstall dox test testclean 60 | 61 | default: $(DEP) obecli$(EXE) 62 | 63 | libobe.a: .depend $(OBJS) $(OBJSCXX) $(OBJASM) 64 | $(AR) rc libobe.a $(OBJS) $(OBJSCXX) $(OBJASM) 65 | $(RANLIB) libobe.a 66 | 67 | $(SONAME): .depend $(OBJS) $(OBJSCXX) $(OBJASM) $(OBJSO) 68 | $(CC) -shared -o $@ $(OBJS) $(OBJASM) $(OBJSO) $(SOFLAGS) $(LDFLAGS) 69 | 70 | obecli$(EXE): $(OBJCLI) libobe.a 71 | $(CC) -o $@ $+ $(LDFLAGSCLI) $(LDFLAGS) 72 | 73 | %.o: %.asm 74 | $(AS) $(ASFLAGS) -o $@ $< 75 | -@ $(if $(STRIP), $(STRIP) -x $@) # delete local/anonymous symbols, so they don't show up in oprofile 76 | 77 | %.o: %.cpp 78 | $(CXX) $(CXXFLAGS) -o $@ $< 79 | 80 | .depend: config.mak 81 | @rm -f .depend 82 | @$(foreach SRC, $(SRCS) $(SRCCLI) $(SRCSO), $(CC) $(CFLAGS) $(SRC) -MT $(SRC:%.c=%.o) -MM -g0 1>> .depend;) 83 | @$(foreach SRC, $(SRCCXX), $(CXX) $(CXXFLAGS) $(SRC) -MT $(SRCCXX:%.cpp=%.o) -MM -g0 1>> .depend;) 84 | 85 | config.mak: 86 | ./configure 87 | 88 | depend: .depend 89 | ifneq ($(wildcard .depend),) 90 | include .depend 91 | endif 92 | 93 | SRC2 = $(SRCS) $(SRCCLI) 94 | 95 | clean: 96 | rm -f $(OBJS) $(OBJSCXX) $(OBJASM) $(OBJCLI) $(OBJSO) $(SONAME) *.a obecli obecli.exe .depend TAGS 97 | rm -f $(SRC2:%.c=%.gcda) $(SRC2:%.c=%.gcno) 98 | - sed -e 's/ *-fprofile-\(generate\|use\)//g' config.mak > config.mak2 && mv config.mak2 config.mak 99 | 100 | distclean: clean 101 | rm -f config.mak config.h config.log 102 | rm -rf test/ 103 | 104 | install: obecli$(EXE) $(SONAME) 105 | install -d $(DESTDIR)$(bindir) 106 | install -d $(DESTDIR)$(includedir) 107 | install -d $(DESTDIR)$(libdir) 108 | install -m 644 libobe.a $(DESTDIR)$(libdir) 109 | install obecli$(EXE) $(DESTDIR)$(bindir) 110 | $(RANLIB) $(DESTDIR)$(libdir)/libobe.a 111 | ifeq ($(SYS),MINGW) 112 | $(if $(SONAME), install -m 755 $(SONAME) $(DESTDIR)$(bindir)) 113 | else 114 | $(if $(SONAME), ln -f -s $(SONAME) $(DESTDIR)$(libdir)/libobe.$(SOSUFFIX)) 115 | $(if $(SONAME), install -m 755 $(SONAME) $(DESTDIR)$(libdir)) 116 | endif 117 | $(if $(IMPLIBNAME), install -m 644 $(IMPLIBNAME) $(DESTDIR)$(libdir)) 118 | 119 | uninstall: 120 | rm -f $(DESTDIR)$(includedir)/obe.h $(DESTDIR)$(libdir)/libobe.a 121 | rm -f $(DESTDIR)$(bindir)/obecli$(EXE) 122 | $(if $(SONAME), rm -f $(DESTDIR)$(libdir)/$(SONAME) $(DESTDIR)$(libdir)/libobe.$(SOSUFFIX)) 123 | 124 | etags: TAGS 125 | 126 | TAGS: 127 | etags $(SRCS) 128 | -------------------------------------------------------------------------------- /input/sdi/decklink/include/DeckLinkAPITypes.h: -------------------------------------------------------------------------------- 1 | /* -LICENSE-START- 2 | ** Copyright (c) 2013 Blackmagic Design 3 | ** 4 | ** Permission is hereby granted, free of charge, to any person or organization 5 | ** obtaining a copy of the software and accompanying documentation covered by 6 | ** this license (the "Software") to use, reproduce, display, distribute, 7 | ** execute, and transmit the Software, and to prepare derivative works of the 8 | ** Software, and to permit third-parties to whom the Software is furnished to 9 | ** do so, all subject to the following: 10 | ** 11 | ** The copyright notices in the Software and this entire statement, including 12 | ** the above license grant, this restriction and the following disclaimer, 13 | ** must be included in all copies of the Software, in whole or in part, and 14 | ** all derivative works of the Software, unless such copies or derivative 15 | ** works are solely in the form of machine-executable object code generated by 16 | ** a source language processor. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | ** FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 21 | ** SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 22 | ** FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 23 | ** ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 24 | ** DEALINGS IN THE SOFTWARE. 25 | ** -LICENSE-END- 26 | */ 27 | 28 | #ifndef BMD_DECKLINKAPITYPES_H 29 | #define BMD_DECKLINKAPITYPES_H 30 | 31 | 32 | #ifndef BMD_CONST 33 | #if defined(_MSC_VER) 34 | #define BMD_CONST __declspec(selectany) static const 35 | #else 36 | #define BMD_CONST static const 37 | #endif 38 | #endif 39 | 40 | // Type Declarations 41 | 42 | typedef int64_t BMDTimeValue; 43 | typedef int64_t BMDTimeScale; 44 | typedef uint32_t BMDTimecodeBCD; 45 | typedef uint32_t BMDTimecodeUserBits; 46 | 47 | // Interface ID Declarations 48 | 49 | BMD_CONST REFIID IID_IDeckLinkTimecode = /* BC6CFBD3-8317-4325-AC1C-1216391E9340 */ {0xBC,0x6C,0xFB,0xD3,0x83,0x17,0x43,0x25,0xAC,0x1C,0x12,0x16,0x39,0x1E,0x93,0x40}; 50 | 51 | /* Enum BMDTimecodeFlags - Timecode flags */ 52 | 53 | typedef uint32_t BMDTimecodeFlags; 54 | enum _BMDTimecodeFlags { 55 | bmdTimecodeFlagDefault = 0, 56 | bmdTimecodeIsDropFrame = 1 << 0 57 | }; 58 | 59 | /* Enum BMDVideoConnection - Video connection types */ 60 | 61 | typedef uint32_t BMDVideoConnection; 62 | enum _BMDVideoConnection { 63 | bmdVideoConnectionSDI = 1 << 0, 64 | bmdVideoConnectionHDMI = 1 << 1, 65 | bmdVideoConnectionOpticalSDI = 1 << 2, 66 | bmdVideoConnectionComponent = 1 << 3, 67 | bmdVideoConnectionComposite = 1 << 4, 68 | bmdVideoConnectionSVideo = 1 << 5 69 | }; 70 | 71 | // Forward Declarations 72 | 73 | class IDeckLinkTimecode; 74 | 75 | /* Interface IDeckLinkTimecode - Used for video frame timecode representation. */ 76 | 77 | class IDeckLinkTimecode : public IUnknown 78 | { 79 | public: 80 | virtual BMDTimecodeBCD GetBCD (void) = 0; 81 | virtual HRESULT GetComponents (/* out */ uint8_t *hours, /* out */ uint8_t *minutes, /* out */ uint8_t *seconds, /* out */ uint8_t *frames) = 0; 82 | virtual HRESULT GetString (/* out */ const char **timecode) = 0; 83 | virtual BMDTimecodeFlags GetFlags (void) = 0; 84 | virtual HRESULT GetTimecodeUserBits (/* out */ BMDTimecodeUserBits *userBits) = 0; 85 | 86 | protected: 87 | virtual ~IDeckLinkTimecode () {}; // call Release method to drop reference count 88 | }; 89 | 90 | /* Functions */ 91 | 92 | extern "C" { 93 | 94 | 95 | }; 96 | 97 | 98 | #endif /* defined(BMD_DECKLINKAPITYPES_H) */ 99 | -------------------------------------------------------------------------------- /filters/audio/audio.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * audio.c: basic audio filtering system 3 | ***************************************************************************** 4 | * Copyright (C) 2012 Open Broadcast Systems Ltd 5 | * 6 | * Authors: Kieran Kunhya 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | */ 22 | 23 | #include "common/common.h" 24 | #include "audio.h" 25 | 26 | static void *start_filter( void *ptr ) 27 | { 28 | obe_raw_frame_t *raw_frame, *split_raw_frame; 29 | obe_aud_filter_params_t *filter_params = ptr; 30 | obe_t *h = filter_params->h; 31 | obe_filter_t *filter = filter_params->filter; 32 | obe_output_stream_t *output_stream; 33 | int num_channels; 34 | 35 | while( 1 ) 36 | { 37 | pthread_mutex_lock( &filter->queue.mutex ); 38 | 39 | while( !filter->queue.size && !filter->cancel_thread ) 40 | pthread_cond_wait( &filter->queue.in_cv, &filter->queue.mutex ); 41 | 42 | if( filter->cancel_thread ) 43 | { 44 | pthread_mutex_unlock( &filter->queue.mutex ); 45 | break; 46 | } 47 | 48 | raw_frame = filter->queue.queue[0]; 49 | pthread_mutex_unlock( &filter->queue.mutex ); 50 | 51 | /* ignore the video track */ 52 | for( int i = 1; i < h->num_encoders; i++ ) 53 | { 54 | output_stream = get_output_stream( h, h->encoders[i]->output_stream_id ); 55 | num_channels = av_get_channel_layout_nb_channels( output_stream->channel_layout ); 56 | 57 | split_raw_frame = new_raw_frame(); 58 | if( !split_raw_frame ) 59 | { 60 | syslog( LOG_ERR, "Malloc failed\n" ); 61 | return NULL; 62 | } 63 | memcpy( split_raw_frame, raw_frame, sizeof(*split_raw_frame) ); 64 | memset( split_raw_frame->audio_frame.audio_data, 0, sizeof(split_raw_frame->audio_frame.audio_data) ); 65 | split_raw_frame->audio_frame.linesize = split_raw_frame->audio_frame.num_channels = 0; 66 | split_raw_frame->audio_frame.channel_layout = output_stream->channel_layout; 67 | 68 | if( av_samples_alloc( split_raw_frame->audio_frame.audio_data, &split_raw_frame->audio_frame.linesize, num_channels, 69 | split_raw_frame->audio_frame.num_samples, split_raw_frame->audio_frame.sample_fmt, 0 ) < 0 ) 70 | { 71 | syslog( LOG_ERR, "Malloc failed\n" ); 72 | return NULL; 73 | } 74 | 75 | /* TODO: offset the channel pointers by the user's request */ 76 | av_samples_copy( split_raw_frame->audio_frame.audio_data, 77 | &raw_frame->audio_frame.audio_data[((output_stream->sdi_audio_pair-1)<<1)+output_stream->mono_channel], 0, 0, 78 | split_raw_frame->audio_frame.num_samples, num_channels, split_raw_frame->audio_frame.sample_fmt ); 79 | 80 | add_to_encode_queue( h, split_raw_frame, h->encoders[i]->output_stream_id ); 81 | } 82 | 83 | remove_from_queue( &filter->queue ); 84 | raw_frame->release_data( raw_frame ); 85 | raw_frame->release_frame( raw_frame ); 86 | raw_frame = NULL; 87 | } 88 | 89 | free( filter_params ); 90 | 91 | return NULL; 92 | } 93 | 94 | const obe_aud_filter_func_t audio_filter = { start_filter }; 95 | -------------------------------------------------------------------------------- /common/bs_read.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * bits.h : Bitstream reading functions 3 | ***************************************************************************** 4 | * Copyright (C) 2003 the VideoLAN team 5 | * $Id$ 6 | * 7 | * Authors: Laurent Aimar 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. 22 | *****************************************************************************/ 23 | 24 | #ifndef OBE_BS_READ_H 25 | #define OBE_BS_READ_H 26 | 27 | /** 28 | * \file 29 | * This file defines functions, structures for handling streams of bits in vlc 30 | * TODO: merge this with x264's bitstream writer if possible 31 | */ 32 | 33 | typedef struct 34 | { 35 | uint8_t *p_start; 36 | uint8_t *p; 37 | uint8_t *p_end; 38 | 39 | ssize_t i_left; /* i_count number of available bits */ 40 | } bs_read_t; 41 | 42 | static inline void bs_read_init( bs_read_t *s, const void *p_data, size_t i_data ) 43 | { 44 | s->p_start = (void *)p_data; 45 | s->p = s->p_start; 46 | s->p_end = s->p_start + i_data; 47 | s->i_left = 8; 48 | } 49 | 50 | static inline int bs_read_pos( const bs_read_t *s ) 51 | { 52 | return( 8 * ( s->p - s->p_start ) + 8 - s->i_left ); 53 | } 54 | 55 | static inline int bs_read_eof( const bs_read_t *s ) 56 | { 57 | return( s->p >= s->p_end ? 1: 0 ); 58 | } 59 | 60 | static inline uint32_t bs_read( bs_read_t *s, int i_count ) 61 | { 62 | static const uint32_t i_mask[33] = 63 | { 0x00, 64 | 0x01, 0x03, 0x07, 0x0f, 65 | 0x1f, 0x3f, 0x7f, 0xff, 66 | 0x1ff, 0x3ff, 0x7ff, 0xfff, 67 | 0x1fff, 0x3fff, 0x7fff, 0xffff, 68 | 0x1ffff, 0x3ffff, 0x7ffff, 0xfffff, 69 | 0x1fffff, 0x3fffff, 0x7fffff, 0xffffff, 70 | 0x1ffffff, 0x3ffffff, 0x7ffffff, 0xfffffff, 71 | 0x1fffffff,0x3fffffff,0x7fffffff,0xffffffff}; 72 | int i_shr; 73 | uint32_t i_result = 0; 74 | 75 | while( i_count > 0 ) 76 | { 77 | if( s->p >= s->p_end ) 78 | { 79 | break; 80 | } 81 | 82 | if( ( i_shr = s->i_left - i_count ) >= 0 ) 83 | { 84 | /* more in the buffer than requested */ 85 | i_result |= ( *s->p >> i_shr )&i_mask[i_count]; 86 | s->i_left -= i_count; 87 | if( s->i_left == 0 ) 88 | { 89 | s->p++; 90 | s->i_left = 8; 91 | } 92 | return( i_result ); 93 | } 94 | else 95 | { 96 | /* less in the buffer than requested */ 97 | i_result |= (*s->p&i_mask[s->i_left]) << -i_shr; 98 | i_count -= s->i_left; 99 | s->p++; 100 | s->i_left = 8; 101 | } 102 | } 103 | 104 | return( i_result ); 105 | } 106 | 107 | static inline uint32_t bs_read1( bs_read_t *s ) 108 | { 109 | if( s->p < s->p_end ) 110 | { 111 | unsigned int i_result; 112 | 113 | s->i_left--; 114 | i_result = ( *s->p >> s->i_left )&0x01; 115 | if( s->i_left == 0 ) 116 | { 117 | s->p++; 118 | s->i_left = 8; 119 | } 120 | return i_result; 121 | } 122 | 123 | return 0; 124 | } 125 | 126 | static inline uint32_t bs_show( bs_read_t *s, int i_count ) 127 | { 128 | bs_read_t s_tmp = *s; 129 | return bs_read( &s_tmp, i_count ); 130 | } 131 | 132 | static inline void bs_skip( bs_read_t *s, ssize_t i_count ) 133 | { 134 | s->i_left -= i_count; 135 | 136 | if( s->i_left <= 0 ) 137 | { 138 | const int i_bytes = ( -s->i_left + 8 ) / 8; 139 | 140 | s->p += i_bytes; 141 | s->i_left += 8 * i_bytes; 142 | } 143 | } 144 | 145 | #endif 146 | -------------------------------------------------------------------------------- /input/sdi/sdi.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * sdi.h: OBE SDI generic headers 3 | ***************************************************************************** 4 | * Copyright (C) 2010 Open Broadcast Systems Ltd. 5 | * 6 | * Authors: Kieran Kunhya 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | *****************************************************************************/ 23 | 24 | #ifndef OBE_SDI_H 25 | #define OBE_SDI_H 26 | 27 | #include "common/common.h" 28 | #undef ZVBI_DEBUG 29 | #include 30 | #include 31 | 32 | /* In microseconds */ 33 | #define SDI_MAX_DELAY 50000 34 | 35 | typedef struct 36 | { 37 | int line; 38 | int identifier; 39 | int unit_id; 40 | int len; 41 | uint8_t *data; 42 | } obe_anc_vbi_t; 43 | 44 | typedef struct 45 | { 46 | int probe; 47 | vbi_raw_decoder vbi_decoder; 48 | 49 | /* Probing */ 50 | int has_probed; 51 | int num_frame_data; 52 | obe_int_frame_data_t *frame_data; 53 | 54 | /* Decoding */ 55 | obe_coded_frame_t *dvb_vbi_frame; 56 | obe_coded_frame_t *dvb_ttx_frame; 57 | 58 | /* VBI */ 59 | int ntsc; 60 | int num_vbi; 61 | vbi_sliced vbi_slices[100]; 62 | int has_vbi_frame; 63 | int has_ttx_frame; 64 | 65 | /* Ancillary VBI */ 66 | int num_anc_vbi; 67 | obe_anc_vbi_t anc_vbi[100]; 68 | 69 | /* Video Index Information */ 70 | AVCRC crc[257]; 71 | AVCRC crc_broken[257]; 72 | 73 | obe_device_t *device; 74 | } obe_sdi_non_display_data_t; 75 | 76 | /* NB: Lines start from 1 */ 77 | typedef struct 78 | { 79 | int format; 80 | int line; 81 | int field_two; /* where relevant */ 82 | } obe_line_number_t; 83 | 84 | /* For NTSC this is not the same as the first coded line */ 85 | const static obe_line_number_t first_active_line[] = 86 | { 87 | { INPUT_VIDEO_FORMAT_PAL, 23 }, 88 | { INPUT_VIDEO_FORMAT_NTSC, 283 }, 89 | { INPUT_VIDEO_FORMAT_720P_50, 26 }, 90 | { INPUT_VIDEO_FORMAT_720P_5994, 26 }, 91 | { INPUT_VIDEO_FORMAT_720P_60, 26 }, 92 | { INPUT_VIDEO_FORMAT_1080I_50, 21 }, 93 | { INPUT_VIDEO_FORMAT_1080I_5994, 21 }, 94 | { INPUT_VIDEO_FORMAT_1080I_60, 21 }, 95 | { INPUT_VIDEO_FORMAT_1080P_2398, 42 }, 96 | { INPUT_VIDEO_FORMAT_1080P_24, 42 }, 97 | { INPUT_VIDEO_FORMAT_1080P_25, 42 }, 98 | { INPUT_VIDEO_FORMAT_1080P_2997, 42 }, 99 | { INPUT_VIDEO_FORMAT_1080P_30, 42 }, 100 | { INPUT_VIDEO_FORMAT_1080P_50, 42 }, 101 | { INPUT_VIDEO_FORMAT_1080P_5994, 42 }, 102 | { INPUT_VIDEO_FORMAT_1080P_60, 42 }, 103 | { -1, -1 }, 104 | }; 105 | 106 | const static obe_line_number_t field_start_lines[] = 107 | { 108 | { INPUT_VIDEO_FORMAT_PAL, 1, 314 }, /* Skip middle line */ 109 | { INPUT_VIDEO_FORMAT_NTSC, 4, 267 }, /* Skip middle line */ 110 | { INPUT_VIDEO_FORMAT_1080I_50, 1, 564 }, 111 | { INPUT_VIDEO_FORMAT_1080I_5994, 1, 564 }, 112 | { INPUT_VIDEO_FORMAT_1080I_60, 1, 564 }, 113 | { -1, -1 }, 114 | }; 115 | 116 | void obe_v210_line_to_nv20_c( uint32_t *src, uint16_t *dst, int width ); 117 | void obe_v210_line_to_uyvy_c( uint32_t *src, uint16_t *dst, int width ); 118 | void obe_yuv422p10_line_to_nv20_c( uint16_t *y, uint16_t *u, uint16_t *v, uint16_t *dst, int width ); 119 | void obe_yuv422p10_line_to_uyvy_c( uint16_t *y, uint16_t *u, uint16_t *v, uint16_t *dst, int width ); 120 | void obe_downscale_line_c( uint16_t *src, uint8_t *dst, int lines ); 121 | void obe_blank_line_nv20_c( uint16_t *dst, int width ); 122 | void obe_blank_line_uyvy_c( uint16_t *dst, int width ); 123 | int add_non_display_services( obe_sdi_non_display_data_t *non_display_data, obe_int_input_stream_t *stream, int location ); 124 | int check_probed_non_display_data( obe_sdi_non_display_data_t *non_display_data, int type ); 125 | int check_active_non_display_data( obe_raw_frame_t *raw_frame, int type ); 126 | int check_user_selected_non_display_data( obe_t *h, int type, int location ); 127 | int add_teletext_service( obe_sdi_non_display_data_t *non_display_data, obe_int_input_stream_t *stream ); 128 | int sdi_next_line( int format, int line_smpte ); 129 | 130 | #endif 131 | -------------------------------------------------------------------------------- /common/linsys/pci_ids.h: -------------------------------------------------------------------------------- 1 | /* pci_ids.h 2 | * 3 | * Linear Systems Ltd PCI device IDs. 4 | * 5 | * Copyright (C) 2004-2009 Linear Systems Ltd. All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of Linear Systems Ltd. nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY LINEAR SYSTEMS LTD. "AS IS" AND ANY 22 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL LINEAR SYSTEMS LTD. OR CONTRIBUTORS 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 26 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 28 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 31 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | * Linear Systems can be contacted at . 34 | * 35 | */ 36 | 37 | #ifndef _PCI_IDS_H 38 | #define _PCI_IDS_H 39 | 40 | #define PCI_VENDOR_ID_LINSYS 0x1254 41 | #define PCI_DEVICE_ID_LINSYS_DVBTX 0x7629 42 | #define PCI_DEVICE_ID_LINSYS_DVBRX 0x7630 43 | #define PCI_DEVICE_ID_LINSYS_DVBFD 0x7643 44 | #define PCI_DEVICE_ID_LINSYS_DVBFDU 0x0065 45 | #define PCI_DEVICE_ID_LINSYS_DVBFDU_R 0x0066 46 | #define PCI_DEVICE_ID_LINSYS_DVBTXU 0x0067 47 | #define PCI_DEVICE_ID_LINSYS_DVBRXU 0x0068 48 | #define PCI_DEVICE_ID_LINSYS_DVBQI 0x0069 49 | #define PCI_DEVICE_ID_LINSYS_MMSA 0x006a 50 | #define PCI_DEVICE_ID_LINSYS_SDIM 0x006b 51 | #define PCI_DEVICE_ID_LINSYS_MMAS 0x006c 52 | #define PCI_DEVICE_ID_LINSYS_DVBFDB 0x006d 53 | #define PCI_DEVICE_ID_LINSYS_DVBFDB_R 0x006e 54 | #define PCI_DEVICE_ID_LINSYS_DVB2FD 0x0073 55 | #define PCI_DEVICE_ID_LINSYS_DVB2FD_R 0x0070 56 | #define PCI_DEVICE_ID_LINSYS_DVB2FD_RS 0x0072 57 | #define PCI_DEVICE_ID_LINSYS_ATSC2FD 0x0074 58 | #define PCI_DEVICE_ID_LINSYS_ATSC2FD_R 0x0071 59 | #define PCI_DEVICE_ID_LINSYS_ATSC2FD_RS 0x00a3 60 | #define PCI_DEVICE_ID_LINSYS_DVBLPFD 0x0075 61 | #define PCI_DEVICE_ID_LINSYS_SDILPFD 0x0076 62 | #define PCI_DEVICE_ID_LINSYS_DVBQLF 0x0077 63 | #define PCI_DEVICE_ID_LINSYS_DVBQO 0x007C 64 | #define PCI_DEVICE_ID_LINSYS_DVBQDUAL 0x007D 65 | #define PCI_DEVICE_ID_LINSYS_DVBQLF4 0x00B5 66 | #define PCI_DEVICE_ID_LINSYS_SDIQI 0x00B1 67 | 68 | /* PCI Express boards */ 69 | #define PCI_DEVICE_ID_LINSYS_DVB2FDE 0x008C 70 | #define PCI_DEVICE_ID_LINSYS_DVB2FDE_R 0x0089 71 | #define PCI_DEVICE_ID_LINSYS_DVB2FDE_RS 0x008B 72 | #define PCI_DEVICE_ID_LINSYS_DVBFDE 0x0099 73 | #define PCI_DEVICE_ID_LINSYS_DVBFDE_R 0x009A 74 | #define PCI_DEVICE_ID_LINSYS_DVBFDEB 0x009D 75 | #define PCI_DEVICE_ID_LINSYS_DVBFDEB_R 0x009E 76 | #define PCI_DEVICE_ID_LINSYS_DVBTXE 0x009B 77 | #define PCI_DEVICE_ID_LINSYS_DVBRXE 0x009C 78 | #define PCI_DEVICE_ID_LINSYS_ATSC2FDE 0x008D 79 | #define PCI_DEVICE_ID_LINSYS_ATSC2FDE_R 0x008A 80 | #define PCI_DEVICE_ID_LINSYS_MMSAE 0x00a0 81 | #define PCI_DEVICE_ID_LINSYS_SDIME 0x009f 82 | #define PCI_DEVICE_ID_LINSYS_MMASE 0x00a1 83 | #define PCI_DEVICE_ID_LINSYS_DVBLPFDE 0x008f 84 | #define PCI_DEVICE_ID_LINSYS_SDIQOE 0x00B4 85 | #define PCI_DEVICE_ID_LINSYS_SDILPFDE 0x0091 86 | #define PCI_DEVICE_ID_LINSYS_SDIQIE 0x00A7 87 | #define PCI_DEVICE_ID_LINSYS_DVBQDUALE 0x0086 88 | #define PCI_DEVICE_ID_LINSYS_DVBLPQOE 0x0095 89 | #define PCI_DEVICE_ID_LINSYS_DVBLPQOE_MINIBNC 0x00AC 90 | #define PCI_DEVICE_ID_LINSYS_DVBQOE 0x0085 91 | #define PCI_DEVICE_ID_LINSYS_DVBQIE 0x0084 92 | #define PCI_DEVICE_ID_LINSYS_DVBLPQDUALE 0x0096 93 | #define PCI_DEVICE_ID_LINSYS_DVBLPQDUALE_MINIBNC 0x00AD 94 | #define PCI_DEVICE_ID_LINSYS_DVBLPQLF 0x00B9 95 | #define PCI_DEVICE_ID_LINSYS_DVBLPQLF_MINIBNC 0x00BA 96 | #define PCI_DEVICE_ID_LINSYS_DVBLPQLF_HEADER 0x00BB 97 | #define PCI_DEVICE_ID_LINSYS_DVBQ3IOE 0x0087 98 | #define PCI_DEVICE_ID_LINSYS_DVBQ3INOE 0x0088 99 | #define PCI_DEVICE_ID_LINSYS_DVBLPTXE 0x00C0 100 | #define PCI_DEVICE_ID_LINSYS_DVBLPRXE 0x00BF 101 | #define PCI_DEVICE_ID_LINSYS_HDSDITXE 0x00C1 102 | #define PCI_DEVICE_ID_LINSYS_HDSDIQI 0x00B6 103 | #define PCI_DEVICE_ID_LINSYS_HDSDIRXE 0x00C8 104 | 105 | 106 | #endif 107 | 108 | -------------------------------------------------------------------------------- /input/sdi/decklink/include/DeckLinkAPIDispatch.cpp: -------------------------------------------------------------------------------- 1 | /* -LICENSE-START- 2 | ** Copyright (c) 2009 Blackmagic Design 3 | ** 4 | ** Permission is hereby granted, free of charge, to any person or organization 5 | ** obtaining a copy of the software and accompanying documentation covered by 6 | ** this license (the "Software") to use, reproduce, display, distribute, 7 | ** execute, and transmit the Software, and to prepare derivative works of the 8 | ** Software, and to permit third-parties to whom the Software is furnished to 9 | ** do so, all subject to the following: 10 | ** 11 | ** The copyright notices in the Software and this entire statement, including 12 | ** the above license grant, this restriction and the following disclaimer, 13 | ** must be included in all copies of the Software, in whole or in part, and 14 | ** all derivative works of the Software, unless such copies or derivative 15 | ** works are solely in the form of machine-executable object code generated by 16 | ** a source language processor. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | ** FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 21 | ** SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 22 | ** FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 23 | ** ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 24 | ** DEALINGS IN THE SOFTWARE. 25 | ** -LICENSE-END- 26 | **/ 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #include "DeckLinkAPI.h" 33 | 34 | #define kDeckLinkAPI_Name "libDeckLinkAPI.so" 35 | #define KDeckLinkPreviewAPI_Name "libDeckLinkPreviewAPI.so" 36 | 37 | typedef IDeckLinkIterator* (*CreateIteratorFunc)(void); 38 | typedef IDeckLinkAPIInformation* (*CreateAPIInformationFunc)(void); 39 | typedef IDeckLinkGLScreenPreviewHelper* (*CreateOpenGLScreenPreviewHelperFunc)(void); 40 | typedef IDeckLinkVideoConversion* (*CreateVideoConversionInstanceFunc)(void); 41 | 42 | static pthread_once_t gDeckLinkOnceControl = PTHREAD_ONCE_INIT; 43 | static pthread_once_t gPreviewOnceControl = PTHREAD_ONCE_INIT; 44 | 45 | static bool gLoadedDeckLinkAPI = false; 46 | 47 | static CreateIteratorFunc gCreateIteratorFunc = NULL; 48 | static CreateAPIInformationFunc gCreateAPIInformationFunc = NULL; 49 | static CreateOpenGLScreenPreviewHelperFunc gCreateOpenGLPreviewFunc = NULL; 50 | static CreateVideoConversionInstanceFunc gCreateVideoConversionFunc = NULL; 51 | 52 | void InitDeckLinkAPI (void) 53 | { 54 | void *libraryHandle; 55 | 56 | libraryHandle = dlopen(kDeckLinkAPI_Name, RTLD_NOW|RTLD_GLOBAL); 57 | if (!libraryHandle) 58 | { 59 | fprintf(stderr, "%s\n", dlerror()); 60 | return; 61 | } 62 | 63 | gLoadedDeckLinkAPI = true; 64 | 65 | gCreateIteratorFunc = (CreateIteratorFunc)dlsym(libraryHandle, "CreateDeckLinkIteratorInstance_0002"); 66 | if (!gCreateIteratorFunc) 67 | fprintf(stderr, "%s\n", dlerror()); 68 | gCreateAPIInformationFunc = (CreateAPIInformationFunc)dlsym(libraryHandle, "CreateDeckLinkAPIInformationInstance_0001"); 69 | if (!gCreateAPIInformationFunc) 70 | fprintf(stderr, "%s\n", dlerror()); 71 | gCreateVideoConversionFunc = (CreateVideoConversionInstanceFunc)dlsym(libraryHandle, "CreateVideoConversionInstance_0001"); 72 | if (!gCreateVideoConversionFunc) 73 | fprintf(stderr, "%s\n", dlerror()); 74 | } 75 | 76 | void InitDeckLinkPreviewAPI (void) 77 | { 78 | void *libraryHandle; 79 | 80 | libraryHandle = dlopen(KDeckLinkPreviewAPI_Name, RTLD_NOW|RTLD_GLOBAL); 81 | if (!libraryHandle) 82 | { 83 | fprintf(stderr, "%s\n", dlerror()); 84 | return; 85 | } 86 | gCreateOpenGLPreviewFunc = (CreateOpenGLScreenPreviewHelperFunc)dlsym(libraryHandle, "CreateOpenGLScreenPreviewHelper_0001"); 87 | if (!gCreateOpenGLPreviewFunc) 88 | fprintf(stderr, "%s\n", dlerror()); 89 | } 90 | 91 | bool IsDeckLinkAPIPresent (void) 92 | { 93 | // If the DeckLink API dynamic library was successfully loaded, return this knowledge to the caller 94 | return gLoadedDeckLinkAPI; 95 | } 96 | 97 | IDeckLinkIterator* CreateDeckLinkIteratorInstance (void) 98 | { 99 | pthread_once(&gDeckLinkOnceControl, InitDeckLinkAPI); 100 | 101 | if (gCreateIteratorFunc == NULL) 102 | return NULL; 103 | return gCreateIteratorFunc(); 104 | } 105 | 106 | IDeckLinkAPIInformation* CreateDeckLinkAPIInformationInstance (void) 107 | { 108 | pthread_once(&gDeckLinkOnceControl, InitDeckLinkAPI); 109 | 110 | if (gCreateAPIInformationFunc == NULL) 111 | return NULL; 112 | return gCreateAPIInformationFunc(); 113 | } 114 | 115 | IDeckLinkGLScreenPreviewHelper* CreateOpenGLScreenPreviewHelper (void) 116 | { 117 | pthread_once(&gDeckLinkOnceControl, InitDeckLinkAPI); 118 | pthread_once(&gPreviewOnceControl, InitDeckLinkPreviewAPI); 119 | 120 | if (gCreateOpenGLPreviewFunc == NULL) 121 | return NULL; 122 | return gCreateOpenGLPreviewFunc(); 123 | } 124 | 125 | IDeckLinkVideoConversion* CreateVideoConversionInstance (void) 126 | { 127 | pthread_once(&gDeckLinkOnceControl, InitDeckLinkAPI); 128 | 129 | if (gCreateVideoConversionFunc == NULL) 130 | return NULL; 131 | return gCreateVideoConversionFunc(); 132 | } 133 | 134 | -------------------------------------------------------------------------------- /input/sdi/linsys/include/sdi.h: -------------------------------------------------------------------------------- 1 | /* sdi.h 2 | * 3 | * Shared header file for the Linux user-space API for 4 | * Linear Systems Ltd. SMPTE 259M-C interface boards. 5 | * 6 | * Copyright (C) 2004-2010 Linear Systems Ltd. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * 1. Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Linear Systems Ltd. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY LINEAR SYSTEMS LTD. "AS IS" AND ANY 23 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL LINEAR SYSTEMS LTD. OR CONTRIBUTORS 26 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 27 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 29 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 31 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 32 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Linear Systems can be contacted at . 35 | * 36 | */ 37 | 38 | #ifndef _SDI_H 39 | #define _SDI_H 40 | 41 | /* Driver info */ 42 | #define SDI_DRIVER_NAME "sdi" 43 | 44 | #define SDI_MAJOR 121 /* Set to 0 for dynamic allocation. 45 | * Otherwise, 121 is available. 46 | * See /usr/src/linux/Documentation/devices.txt */ 47 | 48 | #define SDI_TX_BUFFERS_MIN 2 /* This must be at least 2 */ 49 | /* The minimum transmit buffer size must be positive, divisible by 4, 50 | * and large enough that the buffers aren't transferred to the onboard FIFOs 51 | * too quickly for the machine to handle the interrupts. 52 | * This is especially a problem at startup, when the FIFOs are empty. 53 | * Relevant factors include onboard FIFO size, PCI bus throughput, 54 | * processor speed, and interrupt latency. */ 55 | #define SDI_TX_BUFSIZE_MIN 1024 56 | #define SDI_RX_BUFFERS_MIN 2 /* This must be at least 2 */ 57 | #define SDI_RX_BUFSIZE_MIN 8 /* This must be positive and divisible by 4 */ 58 | 59 | #define SDI_TX_BUFFERS 25 /* This must be at least 2 */ 60 | #define SDI_TX_BUFSIZE 1235520 /* This must be positive and divisible by 4 */ 61 | #define SDI_RX_BUFFERS 25 /* This must be at least 2 */ 62 | #define SDI_RX_BUFSIZE 1235520 /* This must be positive and divisible by 4 */ 63 | 64 | /* Ioctl () definitions */ 65 | #define SDI_IOC_MAGIC '=' /* This ioctl magic number is currently free. See 66 | * /usr/src/linux/Documentation/ioctl-number.txt */ 67 | 68 | #define SDI_IOC_TXGETCAP _IOR(SDI_IOC_MAGIC, 1, unsigned int) 69 | #define SDI_IOC_TXGETEVENTS _IOR(SDI_IOC_MAGIC, 2, unsigned int) 70 | #define SDI_IOC_TXGETBUFLEVEL _IOR(SDI_IOC_MAGIC, 3, unsigned int) 71 | #define SDI_IOC_TXGETTXD _IOR(SDI_IOC_MAGIC, 4, int) 72 | 73 | #define SDI_IOC_RXGETCAP _IOR(SDI_IOC_MAGIC, 65, unsigned int) 74 | #define SDI_IOC_RXGETEVENTS _IOR(SDI_IOC_MAGIC, 66, unsigned int) 75 | #define SDI_IOC_RXGETBUFLEVEL _IOR(SDI_IOC_MAGIC, 67, unsigned int) 76 | #define SDI_IOC_RXGETCARRIER _IOR(SDI_IOC_MAGIC, 68, int) 77 | #define SDI_IOC_RXGETSTATUS _IOR(SDI_IOC_MAGIC, 69, int) 78 | 79 | #define SDI_IOC_GETID _IOR(SDI_IOC_MAGIC, 129, unsigned int) 80 | #define SDI_IOC_GETVERSION _IOR(SDI_IOC_MAGIC, 130, unsigned int) 81 | /* Provide compatibility with applications compiled for older API */ 82 | #define SDI_IOC_QBUF_DEPRECATED _IOR(SDI_IOC_MAGIC, 131, unsigned int) 83 | #define SDI_IOC_QBUF_DEPRECATED2 _IOW(SDI_IOC_MAGIC, 131, unsigned int) 84 | #define SDI_IOC_QBUF _IO(SDI_IOC_MAGIC, 131) 85 | /* Provide compatibility with applications compiled for older API */ 86 | #define SDI_IOC_DQBUF_DEPRECATED _IOR(SDI_IOC_MAGIC, 132, unsigned int) 87 | #define SDI_IOC_DQBUF_DEPRECATED2 _IOW(SDI_IOC_MAGIC, 132, unsigned int) 88 | #define SDI_IOC_DQBUF _IO(SDI_IOC_MAGIC, 132) 89 | 90 | /* Transmitter event flag bit locations */ 91 | #define SDI_EVENT_TX_BUFFER_ORDER 0 92 | #define SDI_EVENT_TX_BUFFER (1 << SDI_EVENT_TX_BUFFER_ORDER) 93 | #define SDI_EVENT_TX_FIFO_ORDER 1 94 | #define SDI_EVENT_TX_FIFO (1 << SDI_EVENT_TX_FIFO_ORDER) 95 | #define SDI_EVENT_TX_DATA_ORDER 2 96 | #define SDI_EVENT_TX_DATA (1 << SDI_EVENT_TX_DATA_ORDER) 97 | 98 | /* Receiver event flag bit locations */ 99 | #define SDI_EVENT_RX_BUFFER_ORDER 0 100 | #define SDI_EVENT_RX_BUFFER (1 << SDI_EVENT_RX_BUFFER_ORDER) 101 | #define SDI_EVENT_RX_FIFO_ORDER 1 102 | #define SDI_EVENT_RX_FIFO (1 << SDI_EVENT_RX_FIFO_ORDER) 103 | #define SDI_EVENT_RX_CARRIER_ORDER 2 104 | #define SDI_EVENT_RX_CARRIER (1 << SDI_EVENT_RX_CARRIER_ORDER) 105 | 106 | /* Interface capabilities */ 107 | #define SDI_CAP_TX_RXCLKSRC 0x00000001 108 | 109 | /* Transmitter clock source settings */ 110 | #define SDI_CTL_TX_CLKSRC_ONBOARD 0 111 | #define SDI_CTL_TX_CLKSRC_EXT 1 112 | #define SDI_CTL_TX_CLKSRC_RX 2 113 | 114 | /* Mode settings */ 115 | #define SDI_CTL_MODE_8BIT 0 116 | #define SDI_CTL_MODE_10BIT 1 117 | 118 | #endif 119 | 120 | -------------------------------------------------------------------------------- /encoders/smoothing.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * /encoders/video/smoothing.c : Video encoder output smoothing 3 | ***************************************************************************** 4 | * Copyright (C) 2010 Open Broadcast Systems Ltd. 5 | * 6 | * Authors: Kieran Kunhya 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | *****************************************************************************/ 23 | 24 | #include "common/common.h" 25 | 26 | static void *start_smoothing( void *ptr ) 27 | { 28 | obe_t *h = ptr; 29 | int num_enc_smoothing_frames = 0, buffer_frames = 0; 30 | int64_t start_dts = -1, start_pts = -1, last_clock = -1; 31 | obe_coded_frame_t *coded_frame = NULL; 32 | 33 | struct sched_param param = {0}; 34 | param.sched_priority = 99; 35 | pthread_setschedparam( pthread_self(), SCHED_FIFO, ¶m ); 36 | 37 | /* FIXME: when we have soft pulldown this will need changing */ 38 | if( h->obe_system == OBE_SYSTEM_TYPE_GENERIC ) 39 | { 40 | for( int i = 0; i < h->num_encoders; i++ ) 41 | { 42 | if( h->encoders[i]->is_video ) 43 | { 44 | pthread_mutex_lock( &h->encoders[i]->queue.mutex ); 45 | while( !h->encoders[i]->is_ready ) 46 | pthread_cond_wait( &h->encoders[i]->queue.in_cv, &h->encoders[i]->queue.mutex ); 47 | x264_param_t *params = h->encoders[i]->encoder_params; 48 | buffer_frames = params->sc.i_buffer_size; 49 | pthread_mutex_unlock( &h->encoders[i]->queue.mutex ); 50 | break; 51 | } 52 | } 53 | } 54 | 55 | //int64_t send_delta = 0; 56 | 57 | while( 1 ) 58 | { 59 | pthread_mutex_lock( &h->enc_smoothing_queue.mutex ); 60 | 61 | while( h->enc_smoothing_queue.size == num_enc_smoothing_frames && !h->cancel_enc_smoothing_thread ) 62 | pthread_cond_wait( &h->enc_smoothing_queue.in_cv, &h->enc_smoothing_queue.mutex ); 63 | 64 | if( h->cancel_enc_smoothing_thread ) 65 | { 66 | pthread_mutex_unlock( &h->enc_smoothing_queue.mutex ); 67 | break; 68 | } 69 | 70 | num_enc_smoothing_frames = h->enc_smoothing_queue.size; 71 | 72 | if( !h->enc_smoothing_buffer_complete ) 73 | { 74 | if( num_enc_smoothing_frames >= buffer_frames ) 75 | { 76 | h->enc_smoothing_buffer_complete = 1; 77 | start_dts = -1; 78 | } 79 | else 80 | { 81 | pthread_mutex_unlock( &h->enc_smoothing_queue.mutex ); 82 | continue; 83 | } 84 | } 85 | 86 | // printf("\n smoothed frames %i \n", num_enc_smoothing_frames ); 87 | 88 | coded_frame = h->enc_smoothing_queue.queue[0]; 89 | pthread_mutex_unlock( &h->enc_smoothing_queue.mutex ); 90 | 91 | /* The terminology can be a cause for confusion: 92 | * pts refers to the pts from the input which is monotonic 93 | * dts refers to the dts out of the encoder which is monotonic */ 94 | 95 | pthread_mutex_lock( &h->obe_clock_mutex ); 96 | 97 | //printf("\n dts gap %"PRIi64" \n", coded_frame->real_dts - start_dts ); 98 | //printf("\n pts gap %"PRIi64" \n", h->obe_clock_last_pts - start_pts ); 99 | 100 | last_clock = h->obe_clock_last_pts; 101 | 102 | if( start_dts == -1 ) 103 | { 104 | start_dts = coded_frame->real_dts; 105 | /* Wait until the next clock tick */ 106 | while( last_clock == h->obe_clock_last_pts && !h->cancel_enc_smoothing_thread ) 107 | pthread_cond_wait( &h->obe_clock_cv, &h->obe_clock_mutex ); 108 | start_pts = h->obe_clock_last_pts; 109 | } 110 | else if( coded_frame->real_dts - start_dts > h->obe_clock_last_pts - start_pts ) 111 | { 112 | //printf("\n waiting \n"); 113 | while( last_clock == h->obe_clock_last_pts && !h->cancel_enc_smoothing_thread ) 114 | pthread_cond_wait( &h->obe_clock_cv, &h->obe_clock_mutex ); 115 | } 116 | /* otherwise, continue since the frame is late */ 117 | 118 | pthread_mutex_unlock( &h->obe_clock_mutex ); 119 | 120 | add_to_queue( &h->mux_queue, coded_frame ); 121 | 122 | //printf("\n send_delta %"PRIi64" \n", get_input_clock_in_mpeg_ticks( h ) - send_delta ); 123 | //send_delta = get_input_clock_in_mpeg_ticks( h ); 124 | 125 | remove_from_queue( &h->enc_smoothing_queue ); 126 | pthread_mutex_lock( &h->enc_smoothing_queue.mutex ); 127 | h->enc_smoothing_last_exit_time = get_input_clock_in_mpeg_ticks( h ); 128 | pthread_mutex_unlock( &h->enc_smoothing_queue.mutex ); 129 | num_enc_smoothing_frames = 0; 130 | } 131 | 132 | return NULL; 133 | } 134 | 135 | const obe_smoothing_func_t enc_smoothing = { start_smoothing }; 136 | -------------------------------------------------------------------------------- /input/sdi/linsys/include/sdiaudio.h: -------------------------------------------------------------------------------- 1 | /* sdiaudio.h 2 | * 3 | * Shared header file for the Linux user-space API for 4 | * Linear Systems Ltd. SMPTE 292M and SMPTE 259M-C Audio interface boards. 5 | * 6 | * Copyright (C) 2009-2010 Linear Systems Ltd. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * 1. Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Linear Systems Ltd. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY LINEAR SYSTEMS LTD. "AS IS" AND ANY 23 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL LINEAR SYSTEMS LTD. OR CONTRIBUTORS 26 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 27 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 29 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 31 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 32 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Linear Systems can be contacted at . 35 | * 36 | */ 37 | 38 | #ifndef _SDIAUDIO_H 39 | #define _SDIAUDIO_H 40 | 41 | /* Driver info */ 42 | #define SDIAUDIO_DRIVER_NAME "sdiaudio" 43 | 44 | #define SDIAUDIO_MAJOR 0 /* Set to 0 for dynamic allocation. 45 | * See /usr/src/linux/Documentation/devices.txt */ 46 | 47 | #define SDIAUDIO_TX_BUFFERS_MIN 2 /* This must be at least 2 */ 48 | /* The minimum transmit buffer size must be positive, divisible by 4, 49 | * and large enough that the buffers aren't transferred to the onboard FIFOs 50 | * too quickly for the machine to handle the interrupts. 51 | * This is especially a problem at startup, when the FIFOs are empty. 52 | * Relevant factors include onboard FIFO size, PCI bus throughput, 53 | * processor speed, and interrupt latency. */ 54 | #define SDIAUDIO_TX_BUFSIZE_MIN 1024 55 | #define SDIAUDIO_RX_BUFFERS_MIN 2 /* This must be at least 2 */ 56 | #define SDIAUDIO_RX_BUFSIZE_MIN 8 /* This must be positive and divisible by 4 */ 57 | 58 | #define SDIAUDIO_TX_BUFFERS 30 /* This must be at least 2 */ 59 | #define SDIAUDIO_TX_BUFSIZE 6400 /* This must be positive and divisible by 4 */ 60 | #define SDIAUDIO_RX_BUFFERS 30 /* This must be at least 2 */ 61 | #define SDIAUDIO_RX_BUFSIZE 6400 /* This must be positive and divisible by 4 */ 62 | 63 | /* Ioctl () definitions */ 64 | #define SDIAUDIO_IOC_MAGIC '~' /* This ioctl magic number is currently free. See 65 | * /usr/src/linux/Documentation/ioctl-number.txt */ 66 | 67 | #define SDIAUDIO_IOC_TXGETCAP _IOR(SDIAUDIO_IOC_MAGIC, 1, unsigned int) 68 | #define SDIAUDIO_IOC_TXGETEVENTS _IOR(SDIAUDIO_IOC_MAGIC, 2, unsigned int) 69 | #define SDIAUDIO_IOC_TXGETBUFLEVEL _IOR(SDIAUDIO_IOC_MAGIC, 3, unsigned int) 70 | #define SDIAUDIO_IOC_TXGETTXD _IOR(SDIAUDIO_IOC_MAGIC, 4, int) 71 | 72 | #define SDIAUDIO_IOC_RXGETCAP _IOR(SDIAUDIO_IOC_MAGIC, 65, unsigned int) 73 | #define SDIAUDIO_IOC_RXGETEVENTS _IOR(SDIAUDIO_IOC_MAGIC, 66, unsigned int) 74 | #define SDIAUDIO_IOC_RXGETBUFLEVEL _IOR(SDIAUDIO_IOC_MAGIC, 67, unsigned int) 75 | #define SDIAUDIO_IOC_RXGETCARRIER _IOR(SDIAUDIO_IOC_MAGIC, 68, int) 76 | #define SDIAUDIO_IOC_RXGETSTATUS _IOR(SDIAUDIO_IOC_MAGIC, 69, int) 77 | #define SDIAUDIO_IOC_RXGETAUDIOGR0ERROR _IOR(SDIAUDIO_IOC_MAGIC, 70, unsigned int) 78 | #define SDIAUDIO_IOC_RXGETAUDIOGR0DELAYA _IOR(SDIAUDIO_IOC_MAGIC, 71, unsigned int) 79 | #define SDIAUDIO_IOC_RXGETAUDIOGR0DELAYB _IOR(SDIAUDIO_IOC_MAGIC, 72, unsigned int) 80 | #define SDIAUDIO_IOC_RXGETNONAUDIO _IOR(SDIAUDIO_IOC_MAGIC, 73, unsigned int) 81 | #define SDIAUDIO_IOC_RXGETAUDSTAT _IOR(SDIAUDIO_IOC_MAGIC, 74, unsigned int) 82 | #define SDIAUDIO_IOC_RXGETAUDRATE _IOR(SDIAUDIO_IOC_MAGIC, 75, unsigned int) 83 | 84 | #define SDIAUDIO_IOC_GETID _IOR(SDIAUDIO_IOC_MAGIC, 129, unsigned int) 85 | #define SDIAUDIO_IOC_GETVERSION _IOR(SDIAUDIO_IOC_MAGIC, 130, unsigned int) 86 | /* Provide compatibility with applications compiled for older API */ 87 | #define SDIAUDIO_IOC_QBUF_DEPRECATED _IOW(SDIAUDIO_IOC_MAGIC, 131, unsigned int) 88 | #define SDIAUDIO_IOC_QBUF _IO(SDIAUDIO_IOC_MAGIC, 131) 89 | /* Provide compatibility with applications compiled for older API */ 90 | #define SDIAUDIO_IOC_DQBUF_DEPRECATED _IOW(SDIAUDIO_IOC_MAGIC, 132, unsigned int) 91 | #define SDIAUDIO_IOC_DQBUF _IO(SDIAUDIO_IOC_MAGIC, 132) 92 | 93 | /* Transmitter event flag bit locations */ 94 | #define SDIAUDIO_EVENT_TX_BUFFER_ORDER 0 95 | #define SDIAUDIO_EVENT_TX_BUFFER (1 << SDIAUDIO_EVENT_TX_BUFFER_ORDER) 96 | #define SDIAUDIO_EVENT_TX_FIFO_ORDER 1 97 | #define SDIAUDIO_EVENT_TX_FIFO (1 << SDIAUDIO_EVENT_TX_FIFO_ORDER) 98 | #define SDIAUDIO_EVENT_TX_DATA_ORDER 2 99 | #define SDIAUDIO_EVENT_TX_DATA (1 << SDIAUDIO_EVENT_TX_DATA_ORDER) 100 | 101 | /* Receiver event flag bit locations */ 102 | #define SDIAUDIO_EVENT_RX_BUFFER_ORDER 0 103 | #define SDIAUDIO_EVENT_RX_BUFFER (1 << SDIAUDIO_EVENT_RX_BUFFER_ORDER) 104 | #define SDIAUDIO_EVENT_RX_FIFO_ORDER 1 105 | #define SDIAUDIO_EVENT_RX_FIFO (1 << SDIAUDIO_EVENT_RX_FIFO_ORDER) 106 | #define SDIAUDIO_EVENT_RX_CARRIER_ORDER 2 107 | #define SDIAUDIO_EVENT_RX_CARRIER (1 << SDIAUDIO_EVENT_RX_CARRIER_ORDER) 108 | #define SDIAUDIO_EVENT_RX_DATA_ORDER 3 109 | #define SDIAUDIO_EVENT_RX_DATA (1 << SDIAUDIO_EVENT_RX_DATA_ORDER) 110 | 111 | /* Interface capabilities */ 112 | #define SDIAUDIO_CAP_RX_CD 0x00000001 113 | #define SDIAUDIO_CAP_RX_DATA 0x00000002 114 | #define SDIAUDIO_CAP_RX_STATS 0x00000004 115 | #define SDIAUDIO_CAP_RX_NONAUDIO 0x00000008 116 | #define SDIAUDIO_CAP_RX_24BIT 0x00000010 117 | 118 | /* Audio sample size */ 119 | #define SDIAUDIO_CTL_AUDSAMP_SZ_16 16 /* 16 bit */ 120 | #define SDIAUDIO_CTL_AUDSAMP_SZ_24 24 /* 24 bit */ 121 | #define SDIAUDIO_CTL_AUDSAMP_SZ_32 32 /* 32 bit */ 122 | 123 | /* Audio channel enable */ 124 | #define SDIAUDIO_CTL_AUDCH_EN_0 0 /* 0 channel/disable audio */ 125 | #define SDIAUDIO_CTL_AUDCH_EN_2 2 /* 2 channel */ 126 | #define SDIAUDIO_CTL_AUDCH_EN_4 4 /* 4 channel */ 127 | #define SDIAUDIO_CTL_AUDCH_EN_6 6 /* 6 channel */ 128 | #define SDIAUDIO_CTL_AUDCH_EN_8 8 /* 8 channel */ 129 | 130 | #define SDIAUDIO_CTL_PCM_ALLCHANNEL 0x00000000 /* PCM for channel 1 - 8 */ 131 | #define SDIAUDIO_CTL_NONAUDIO_ALLCHANNEL 0x000000ff /* No audio for channel 1 - 8 */ 132 | 133 | /* Active audio channels status */ 134 | #define SDIAUDIO_CTL_ACT_CHAN_0 0x00 /* no audio control packets */ 135 | #define SDIAUDIO_CTL_ACT_CHAN_2 0x03 /* 2 channels */ 136 | #define SDIAUDIO_CTL_ACT_CHAN_4 0x0f /* 4 channels */ 137 | #define SDIAUDIO_CTL_ACT_CHAN_6 0x3f /* 6 channels */ 138 | #define SDIAUDIO_CTL_ACT_CHAN_8 0xff /* 8 channels */ 139 | 140 | /* Audio rate */ 141 | #define SDIAUDIO_CTL_SYNC_48_KHZ 0 /* Synchronous, 48 kHz */ 142 | #define SDIAUDIO_CTL_SYNC_44_1_KHZ 2 /* Synchronous, 44.1 kHz */ 143 | #define SDIAUDIO_CTL_SYNC_32_KHZ 4 /* Synchronous, 32 kHz */ 144 | #define SDIAUDIO_CTL_SYNC_96_KHZ 8 /* Synchronous, 96 kHz */ 145 | #define SDIAUDIO_CTL_SYNC_FREE_RUNNING 14 /* Synchronous, free running */ 146 | #define SDIAUDIO_CTL_ASYNC_48_KHZ 1 /* Asynchronous, 48 kHz */ 147 | #define SDIAUDIO_CTL_ASYNC_44_1_KHZ 3 /* Asynchronous, 44.1 kHz */ 148 | #define SDIAUDIO_CTL_ASYNC_32_KHZ 5 /* Asynchronous, 32 kHz */ 149 | #define SDIAUDIO_CTL_ASYNC_96_KHZ 9 /* Asynchronous, 96 kHz */ 150 | #define SDIAUDIO_CTL_ASYNC_FREE_RUNNING 15 /* Asynchronous, free running */ 151 | 152 | #endif 153 | 154 | -------------------------------------------------------------------------------- /encoders/audio/mp2/twolame.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * twolame.c : twolame encoding functions 3 | ***************************************************************************** 4 | * Copyright (C) 2010 Open Broadcast Systems Ltd. 5 | * 6 | * Authors: Kieran Kunhya 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | ******************************************************************************/ 23 | 24 | #include "common/common.h" 25 | #include "encoders/audio/audio.h" 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #define MP2_AUDIO_BUFFER_SIZE 50000 32 | 33 | static void *start_encoder( void *ptr ) 34 | { 35 | obe_aud_enc_params_t *enc_params = ptr; 36 | obe_t *h = enc_params->h; 37 | obe_encoder_t *encoder = enc_params->encoder; 38 | obe_output_stream_t *stream = enc_params->stream; 39 | obe_raw_frame_t *raw_frame; 40 | obe_coded_frame_t *coded_frame; 41 | 42 | twolame_options *tl_opts = NULL; 43 | int output_size, frame_size, linesize; /* Linesize in libavresample terminology is the entire buffer size for packed formats */ 44 | int64_t cur_pts = -1; 45 | float *audio_buf = NULL; 46 | uint8_t *output_buf = NULL; 47 | AVAudioResampleContext *avr = NULL; 48 | AVFifoBuffer *fifo = NULL; 49 | 50 | /* Lock the mutex until we verify parameters */ 51 | pthread_mutex_lock( &encoder->queue.mutex ); 52 | 53 | tl_opts = twolame_init(); 54 | if( !tl_opts ) 55 | { 56 | fprintf( stderr, "[twolame] could not load options" ); 57 | pthread_mutex_unlock( &encoder->queue.mutex ); 58 | goto end; 59 | } 60 | 61 | /* TODO: setup bitrate reconfig, errors */ 62 | twolame_set_bitrate( tl_opts, stream->bitrate ); 63 | twolame_set_in_samplerate( tl_opts, enc_params->sample_rate ); 64 | twolame_set_out_samplerate( tl_opts, enc_params->sample_rate ); 65 | twolame_set_copyright( tl_opts, 1 ); 66 | twolame_set_original( tl_opts, 1 ); 67 | twolame_set_num_channels( tl_opts, av_get_channel_layout_nb_channels( stream->channel_layout ) ); 68 | twolame_set_error_protection( tl_opts, 1 ); 69 | if( stream->channel_layout == AV_CH_LAYOUT_STEREO ) 70 | twolame_set_mode( tl_opts, stream->mp2_mode-1 ); 71 | 72 | twolame_init_params( tl_opts ); 73 | 74 | frame_size = twolame_get_framelength( tl_opts ) * enc_params->frames_per_pes; 75 | 76 | encoder->is_ready = 1; 77 | /* Broadcast because input and muxer can be stuck waiting for encoder */ 78 | pthread_cond_broadcast( &encoder->queue.in_cv ); 79 | pthread_mutex_unlock( &encoder->queue.mutex ); 80 | 81 | output_buf = malloc( MP2_AUDIO_BUFFER_SIZE ); 82 | if( !output_buf ) 83 | { 84 | fprintf( stderr, "Malloc failed\n" ); 85 | goto end; 86 | } 87 | 88 | avr = avresample_alloc_context(); 89 | if( !avr ) 90 | { 91 | fprintf( stderr, "Malloc failed\n" ); 92 | goto end; 93 | } 94 | 95 | av_opt_set_int( avr, "in_channel_layout", stream->channel_layout, 0 ); 96 | av_opt_set_int( avr, "in_sample_fmt", enc_params->input_sample_format, 0 ); 97 | av_opt_set_int( avr, "in_sample_rate", enc_params->sample_rate, 0 ); 98 | av_opt_set_int( avr, "out_channel_layout", stream->channel_layout, 0 ); 99 | av_opt_set_int( avr, "out_sample_fmt", AV_SAMPLE_FMT_FLT, 0 ); 100 | av_opt_set_int( avr, "dither_method", AV_RESAMPLE_DITHER_TRIANGULAR_NS, 0 ); 101 | 102 | if( avresample_open( avr ) < 0 ) 103 | { 104 | fprintf( stderr, "Could not open AVResample\n" ); 105 | goto end; 106 | } 107 | 108 | /* Setup the output FIFO */ 109 | fifo = av_fifo_alloc( frame_size ); 110 | if( !fifo ) 111 | { 112 | fprintf( stderr, "Malloc failed\n" ); 113 | goto end; 114 | } 115 | 116 | while( 1 ) 117 | { 118 | pthread_mutex_lock( &encoder->queue.mutex ); 119 | 120 | while( !encoder->queue.size && !encoder->cancel_thread ) 121 | pthread_cond_wait( &encoder->queue.in_cv, &encoder->queue.mutex ); 122 | 123 | if( encoder->cancel_thread ) 124 | { 125 | pthread_mutex_unlock( &encoder->queue.mutex ); 126 | break; 127 | } 128 | 129 | raw_frame = encoder->queue.queue[0]; 130 | pthread_mutex_unlock( &encoder->queue.mutex ); 131 | 132 | if( cur_pts == -1 ) 133 | cur_pts = raw_frame->pts; 134 | 135 | /* Allocate the output buffer */ 136 | if( av_samples_alloc( (uint8_t**)&audio_buf, &linesize, av_get_channel_layout_nb_channels( raw_frame->audio_frame.channel_layout ), 137 | raw_frame->audio_frame.linesize, AV_SAMPLE_FMT_FLT, 0 ) < 0 ) 138 | { 139 | syslog( LOG_ERR, "Malloc failed\n" ); 140 | goto end; 141 | } 142 | 143 | if( avresample_convert( avr, NULL, 0, raw_frame->audio_frame.num_samples, raw_frame->audio_frame.audio_data, 144 | raw_frame->audio_frame.linesize, raw_frame->audio_frame.num_samples ) < 0 ) 145 | { 146 | syslog( LOG_ERR, "[twolame] Sample format conversion failed\n" ); 147 | break; 148 | } 149 | 150 | avresample_read( avr, (uint8_t**)&audio_buf, avresample_available( avr ) ); 151 | 152 | output_size = twolame_encode_buffer_float32_interleaved( tl_opts, audio_buf, raw_frame->audio_frame.num_samples, output_buf, MP2_AUDIO_BUFFER_SIZE ); 153 | 154 | if( output_size < 0 ) 155 | { 156 | syslog( LOG_ERR, "[twolame] Encode failed\n" ); 157 | break; 158 | } 159 | 160 | free( audio_buf ); 161 | audio_buf = NULL; 162 | 163 | raw_frame->release_data( raw_frame ); 164 | raw_frame->release_frame( raw_frame ); 165 | remove_from_queue( &encoder->queue ); 166 | 167 | if( av_fifo_realloc2( fifo, av_fifo_size( fifo ) + output_size ) < 0 ) 168 | { 169 | syslog( LOG_ERR, "Malloc failed\n" ); 170 | break; 171 | } 172 | 173 | av_fifo_generic_write( fifo, output_buf, output_size, NULL ); 174 | 175 | while( av_fifo_size( fifo ) >= frame_size ) 176 | { 177 | coded_frame = new_coded_frame( encoder->output_stream_id, frame_size ); 178 | if( !coded_frame ) 179 | { 180 | syslog( LOG_ERR, "Malloc failed\n" ); 181 | goto end; 182 | } 183 | av_fifo_generic_read( fifo, coded_frame->data, frame_size, NULL ); 184 | coded_frame->pts = cur_pts; 185 | coded_frame->random_access = 1; /* Every frame output is a random access point */ 186 | 187 | add_to_queue( &h->mux_queue, coded_frame ); 188 | /* We need to generate PTS because frame sizes have changed */ 189 | cur_pts += (double)MP2_NUM_SAMPLES * OBE_CLOCK * enc_params->frames_per_pes / enc_params->sample_rate; 190 | } 191 | } 192 | 193 | end: 194 | if( output_buf ) 195 | free( output_buf ); 196 | 197 | if( audio_buf ) 198 | free( audio_buf ); 199 | 200 | if( avr ) 201 | avresample_free( &avr ); 202 | 203 | if( fifo ) 204 | av_fifo_free( fifo ); 205 | 206 | if( tl_opts ) 207 | twolame_close( &tl_opts ); 208 | free( enc_params ); 209 | 210 | return NULL; 211 | } 212 | 213 | const obe_aud_enc_func_t twolame_encoder = { start_encoder }; 214 | -------------------------------------------------------------------------------- /input/sdi/decklink/include/DeckLinkAPIModes.h: -------------------------------------------------------------------------------- 1 | /* -LICENSE-START- 2 | ** Copyright (c) 2013 Blackmagic Design 3 | ** 4 | ** Permission is hereby granted, free of charge, to any person or organization 5 | ** obtaining a copy of the software and accompanying documentation covered by 6 | ** this license (the "Software") to use, reproduce, display, distribute, 7 | ** execute, and transmit the Software, and to prepare derivative works of the 8 | ** Software, and to permit third-parties to whom the Software is furnished to 9 | ** do so, all subject to the following: 10 | ** 11 | ** The copyright notices in the Software and this entire statement, including 12 | ** the above license grant, this restriction and the following disclaimer, 13 | ** must be included in all copies of the Software, in whole or in part, and 14 | ** all derivative works of the Software, unless such copies or derivative 15 | ** works are solely in the form of machine-executable object code generated by 16 | ** a source language processor. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | ** FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 21 | ** SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 22 | ** FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 23 | ** ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 24 | ** DEALINGS IN THE SOFTWARE. 25 | ** -LICENSE-END- 26 | */ 27 | 28 | #ifndef BMD_DECKLINKAPIMODES_H 29 | #define BMD_DECKLINKAPIMODES_H 30 | 31 | 32 | #ifndef BMD_CONST 33 | #if defined(_MSC_VER) 34 | #define BMD_CONST __declspec(selectany) static const 35 | #else 36 | #define BMD_CONST static const 37 | #endif 38 | #endif 39 | 40 | // Type Declarations 41 | 42 | 43 | // Interface ID Declarations 44 | 45 | BMD_CONST REFIID IID_IDeckLinkDisplayModeIterator = /* 9C88499F-F601-4021-B80B-032E4EB41C35 */ {0x9C,0x88,0x49,0x9F,0xF6,0x01,0x40,0x21,0xB8,0x0B,0x03,0x2E,0x4E,0xB4,0x1C,0x35}; 46 | BMD_CONST REFIID IID_IDeckLinkDisplayMode = /* 3EB2C1AB-0A3D-4523-A3AD-F40D7FB14E78 */ {0x3E,0xB2,0xC1,0xAB,0x0A,0x3D,0x45,0x23,0xA3,0xAD,0xF4,0x0D,0x7F,0xB1,0x4E,0x78}; 47 | 48 | /* Enum BMDDisplayMode - Video display modes */ 49 | 50 | typedef uint32_t BMDDisplayMode; 51 | enum _BMDDisplayMode { 52 | 53 | /* SD Modes */ 54 | 55 | bmdModeNTSC = /* 'ntsc' */ 0x6E747363, 56 | bmdModeNTSC2398 = /* 'nt23' */ 0x6E743233, // 3:2 pulldown 57 | bmdModePAL = /* 'pal ' */ 0x70616C20, 58 | bmdModeNTSCp = /* 'ntsp' */ 0x6E747370, 59 | bmdModePALp = /* 'palp' */ 0x70616C70, 60 | 61 | /* HD 1080 Modes */ 62 | 63 | bmdModeHD1080p2398 = /* '23ps' */ 0x32337073, 64 | bmdModeHD1080p24 = /* '24ps' */ 0x32347073, 65 | bmdModeHD1080p25 = /* 'Hp25' */ 0x48703235, 66 | bmdModeHD1080p2997 = /* 'Hp29' */ 0x48703239, 67 | bmdModeHD1080p30 = /* 'Hp30' */ 0x48703330, 68 | bmdModeHD1080i50 = /* 'Hi50' */ 0x48693530, 69 | bmdModeHD1080i5994 = /* 'Hi59' */ 0x48693539, 70 | bmdModeHD1080i6000 = /* 'Hi60' */ 0x48693630, // N.B. This _really_ is 60.00 Hz. 71 | bmdModeHD1080p50 = /* 'Hp50' */ 0x48703530, 72 | bmdModeHD1080p5994 = /* 'Hp59' */ 0x48703539, 73 | bmdModeHD1080p6000 = /* 'Hp60' */ 0x48703630, // N.B. This _really_ is 60.00 Hz. 74 | 75 | /* HD 720 Modes */ 76 | 77 | bmdModeHD720p50 = /* 'hp50' */ 0x68703530, 78 | bmdModeHD720p5994 = /* 'hp59' */ 0x68703539, 79 | bmdModeHD720p60 = /* 'hp60' */ 0x68703630, 80 | 81 | /* 2k Modes */ 82 | 83 | bmdMode2k2398 = /* '2k23' */ 0x326B3233, 84 | bmdMode2k24 = /* '2k24' */ 0x326B3234, 85 | bmdMode2k25 = /* '2k25' */ 0x326B3235, 86 | 87 | /* 4k Modes */ 88 | 89 | bmdMode4K2160p2398 = /* '4k23' */ 0x346B3233, 90 | bmdMode4K2160p24 = /* '4k24' */ 0x346B3234, 91 | bmdMode4K2160p25 = /* '4k25' */ 0x346B3235, 92 | bmdMode4K2160p2997 = /* '4k29' */ 0x346B3239, 93 | bmdMode4K2160p30 = /* '4k30' */ 0x346B3330, 94 | 95 | /* Special Modes */ 96 | 97 | bmdModeUnknown = /* 'iunk' */ 0x69756E6B 98 | }; 99 | 100 | /* Enum BMDFieldDominance - Video field dominance */ 101 | 102 | typedef uint32_t BMDFieldDominance; 103 | enum _BMDFieldDominance { 104 | bmdUnknownFieldDominance = 0, 105 | bmdLowerFieldFirst = /* 'lowr' */ 0x6C6F7772, 106 | bmdUpperFieldFirst = /* 'uppr' */ 0x75707072, 107 | bmdProgressiveFrame = /* 'prog' */ 0x70726F67, 108 | bmdProgressiveSegmentedFrame = /* 'psf ' */ 0x70736620 109 | }; 110 | 111 | /* Enum BMDPixelFormat - Video pixel formats supported for output/input */ 112 | 113 | typedef uint32_t BMDPixelFormat; 114 | enum _BMDPixelFormat { 115 | bmdFormat8BitYUV = /* '2vuy' */ 0x32767579, 116 | bmdFormat10BitYUV = /* 'v210' */ 0x76323130, 117 | bmdFormat8BitARGB = 32, 118 | bmdFormat8BitBGRA = /* 'BGRA' */ 0x42475241, 119 | bmdFormat10BitRGB = /* 'r210' */ 0x72323130 // Big-endian RGB 10-bit per component with SMPTE video levels (64-960). Packed as 2:10:10:10 120 | }; 121 | 122 | /* Enum BMDDisplayModeFlags - Flags to describe the characteristics of an IDeckLinkDisplayMode. */ 123 | 124 | typedef uint32_t BMDDisplayModeFlags; 125 | enum _BMDDisplayModeFlags { 126 | bmdDisplayModeSupports3D = 1 << 0, 127 | bmdDisplayModeColorspaceRec601 = 1 << 1, 128 | bmdDisplayModeColorspaceRec709 = 1 << 2 129 | }; 130 | 131 | // Forward Declarations 132 | 133 | class IDeckLinkDisplayModeIterator; 134 | class IDeckLinkDisplayMode; 135 | 136 | /* Interface IDeckLinkDisplayModeIterator - enumerates over supported input/output display modes. */ 137 | 138 | class IDeckLinkDisplayModeIterator : public IUnknown 139 | { 140 | public: 141 | virtual HRESULT Next (/* out */ IDeckLinkDisplayMode **deckLinkDisplayMode) = 0; 142 | 143 | protected: 144 | virtual ~IDeckLinkDisplayModeIterator () {}; // call Release method to drop reference count 145 | }; 146 | 147 | /* Interface IDeckLinkDisplayMode - represents a display mode */ 148 | 149 | class IDeckLinkDisplayMode : public IUnknown 150 | { 151 | public: 152 | virtual HRESULT GetName (/* out */ const char **name) = 0; 153 | virtual BMDDisplayMode GetDisplayMode (void) = 0; 154 | virtual long GetWidth (void) = 0; 155 | virtual long GetHeight (void) = 0; 156 | virtual HRESULT GetFrameRate (/* out */ BMDTimeValue *frameDuration, /* out */ BMDTimeScale *timeScale) = 0; 157 | virtual BMDFieldDominance GetFieldDominance (void) = 0; 158 | virtual BMDDisplayModeFlags GetFlags (void) = 0; 159 | 160 | protected: 161 | virtual ~IDeckLinkDisplayMode () {}; // call Release method to drop reference count 162 | }; 163 | 164 | /* Functions */ 165 | 166 | extern "C" { 167 | 168 | 169 | }; 170 | 171 | 172 | #endif /* defined(BMD_DECKLINKAPIMODES_H) */ 173 | -------------------------------------------------------------------------------- /mux/smoothing.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * mux/ts/smoothing.c : Mux output smoothing 3 | ***************************************************************************** 4 | * Copyright (C) 2012 Open Broadcast Systems Ltd. 5 | * 6 | * Authors: Kieran Kunhya 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | *****************************************************************************/ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include "common/common.h" 29 | 30 | static void *start_smoothing( void *ptr ) 31 | { 32 | obe_t *h = ptr; 33 | int num_muxed_data = 0, buffer_complete = 0; 34 | int64_t start_clock = -1, start_pcr, end_pcr, temporal_vbv_size = 0, cur_pcr; 35 | obe_muxed_data_t **muxed_data = NULL, *start_data, *end_data; 36 | AVFifoBuffer *fifo_data = NULL, *fifo_pcr = NULL; 37 | AVBufferRef **output_buffers = NULL; 38 | 39 | struct sched_param param = {0}; 40 | param.sched_priority = 99; 41 | pthread_setschedparam( pthread_self(), SCHED_FIFO, ¶m ); 42 | 43 | /* This thread buffers one VBV worth of frames */ 44 | fifo_data = av_fifo_alloc( TS_PACKETS_SIZE ); 45 | if( !fifo_data ) 46 | { 47 | fprintf( stderr, "[mux-smoothing] Could not allocate data fifo" ); 48 | return NULL; 49 | } 50 | 51 | fifo_pcr = av_fifo_alloc( 7 * sizeof(int64_t) ); 52 | if( !fifo_pcr ) 53 | { 54 | fprintf( stderr, "[mux-smoothing] Could not allocate pcr fifo" ); 55 | return NULL; 56 | } 57 | 58 | output_buffers = malloc( h->num_outputs * sizeof(*output_buffers) ); 59 | if( !output_buffers ) 60 | { 61 | fprintf( stderr, "[mux-smoothing] Could not allocate output buffers" ); 62 | return NULL; 63 | } 64 | 65 | if( h->obe_system != OBE_SYSTEM_TYPE_LOWEST_LATENCY ) 66 | { 67 | for( int i = 0; i < h->num_encoders; i++ ) 68 | { 69 | if( h->encoders[i]->is_video ) 70 | { 71 | pthread_mutex_lock( &h->encoders[i]->queue.mutex ); 72 | while( !h->encoders[i]->is_ready ) 73 | pthread_cond_wait( &h->encoders[i]->queue.in_cv, &h->encoders[i]->queue.mutex ); 74 | x264_param_t *params = h->encoders[i]->encoder_params; 75 | temporal_vbv_size = av_rescale_q_rnd( 76 | (int64_t)params->rc.i_vbv_buffer_size * params->rc.f_vbv_buffer_init, 77 | (AVRational){1, params->rc.i_vbv_max_bitrate }, (AVRational){ 1, OBE_CLOCK }, AV_ROUND_UP ); 78 | pthread_mutex_unlock( &h->encoders[i]->queue.mutex ); 79 | break; 80 | } 81 | } 82 | } 83 | 84 | while( 1 ) 85 | { 86 | pthread_mutex_lock( &h->mux_smoothing_queue.mutex ); 87 | 88 | while( h->mux_smoothing_queue.size == num_muxed_data && !h->cancel_mux_smoothing_thread ) 89 | pthread_cond_wait( &h->mux_smoothing_queue.in_cv, &h->mux_smoothing_queue.mutex ); 90 | 91 | if( h->cancel_mux_smoothing_thread ) 92 | { 93 | pthread_mutex_unlock( &h->mux_smoothing_queue.mutex ); 94 | break; 95 | } 96 | 97 | num_muxed_data = h->mux_smoothing_queue.size; 98 | 99 | /* Refill the buffer after a drop */ 100 | pthread_mutex_lock( &h->drop_mutex ); 101 | if( h->mux_drop ) 102 | { 103 | syslog( LOG_INFO, "Mux smoothing buffer reset\n" ); 104 | h->mux_drop = 0; 105 | av_fifo_reset( fifo_data ); 106 | av_fifo_reset( fifo_pcr ); 107 | buffer_complete = 0; 108 | start_clock = -1; 109 | } 110 | pthread_mutex_unlock( &h->drop_mutex ); 111 | 112 | if( !buffer_complete ) 113 | { 114 | start_data = h->mux_smoothing_queue.queue[0]; 115 | end_data = h->mux_smoothing_queue.queue[num_muxed_data-1]; 116 | 117 | start_pcr = start_data->pcr_list[0]; 118 | end_pcr = end_data->pcr_list[(end_data->len / 188)-1]; 119 | if( end_pcr - start_pcr >= temporal_vbv_size ) 120 | { 121 | buffer_complete = 1; 122 | start_clock = -1; 123 | } 124 | else 125 | { 126 | pthread_mutex_unlock( &h->mux_smoothing_queue.mutex ); 127 | continue; 128 | } 129 | } 130 | 131 | //printf("\n mux smoothed frames %i \n", num_muxed_data ); 132 | 133 | muxed_data = malloc( num_muxed_data * sizeof(*muxed_data) ); 134 | if( !muxed_data ) 135 | { 136 | pthread_mutex_unlock( &h->mux_smoothing_queue.mutex ); 137 | syslog( LOG_ERR, "Malloc failed\n" ); 138 | return NULL; 139 | } 140 | memcpy( muxed_data, h->mux_smoothing_queue.queue, num_muxed_data * sizeof(*muxed_data) ); 141 | pthread_mutex_unlock( &h->mux_smoothing_queue.mutex ); 142 | 143 | for( int i = 0; i < num_muxed_data; i++ ) 144 | { 145 | if( av_fifo_realloc2( fifo_data, av_fifo_size( fifo_data ) + muxed_data[i]->len ) < 0 ) 146 | { 147 | syslog( LOG_ERR, "Malloc failed\n" ); 148 | return NULL; 149 | } 150 | 151 | av_fifo_generic_write( fifo_data, muxed_data[i]->data, muxed_data[i]->len, NULL ); 152 | 153 | if( av_fifo_realloc2( fifo_pcr, av_fifo_size( fifo_pcr ) + ((muxed_data[i]->len * sizeof(int64_t)) / 188) ) < 0 ) 154 | { 155 | syslog( LOG_ERR, "Malloc failed\n" ); 156 | return NULL; 157 | } 158 | 159 | av_fifo_generic_write( fifo_pcr, muxed_data[i]->pcr_list, (muxed_data[i]->len * sizeof(int64_t)) / 188, NULL ); 160 | 161 | remove_from_queue( &h->mux_smoothing_queue ); 162 | destroy_muxed_data( muxed_data[i] ); 163 | } 164 | 165 | free( muxed_data ); 166 | muxed_data = NULL; 167 | num_muxed_data = 0; 168 | 169 | while( av_fifo_size( fifo_data ) >= TS_PACKETS_SIZE ) 170 | { 171 | output_buffers[0] = av_buffer_alloc( TS_PACKETS_SIZE + 7 * sizeof(int64_t) ); 172 | av_fifo_generic_read( fifo_pcr, output_buffers[0]->data, 7 * sizeof(int64_t), NULL ); 173 | av_fifo_generic_read( fifo_data, &output_buffers[0]->data[7 * sizeof(int64_t)], TS_PACKETS_SIZE, NULL ); 174 | 175 | for( int i = 1; i < h->num_outputs; i++ ) 176 | { 177 | output_buffers[i] = av_buffer_ref( output_buffers[0] ); 178 | if( !output_buffers[i] ) 179 | { 180 | syslog( LOG_ERR, "Malloc failed\n" ); 181 | return NULL; 182 | } 183 | } 184 | 185 | cur_pcr = AV_RN64( output_buffers[0]->data ); 186 | 187 | if( start_clock != -1 ) 188 | { 189 | sleep_input_clock( h, cur_pcr - start_pcr + start_clock ); 190 | } 191 | 192 | if( start_clock == -1 ) 193 | { 194 | start_clock = get_input_clock_in_mpeg_ticks( h ); 195 | start_pcr = cur_pcr; 196 | } 197 | 198 | for( int i = 0; i < h->num_outputs; i++ ) 199 | { 200 | if( add_to_queue( &h->outputs[i]->queue, output_buffers[i] ) < 0 ) 201 | return NULL; 202 | output_buffers[i] = NULL; 203 | } 204 | } 205 | } 206 | 207 | av_fifo_free( fifo_data ); 208 | av_fifo_free( fifo_pcr ); 209 | free( output_buffers ); 210 | 211 | return NULL; 212 | } 213 | 214 | const obe_smoothing_func_t mux_smoothing = { start_smoothing }; 215 | -------------------------------------------------------------------------------- /output/ip/ip.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * ip.c : IP output functions 3 | ***************************************************************************** 4 | * Copyright (C) 2010 Open Broadcast Systems Ltd. 5 | * 6 | * Large Portions of this code originate from FFmpeg 7 | * Authors: Kieran Kunhya 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 22 | * 23 | *****************************************************************************/ 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include "common/common.h" 30 | #include "common/network/network.h" 31 | #include "common/network/udp/udp.h" 32 | #include "output/output.h" 33 | #include "common/bitstream.h" 34 | 35 | #define RTP_VERSION 2 36 | #define MPEG_TS_PAYLOAD_TYPE 33 37 | #define RTP_HEADER_SIZE 12 38 | 39 | #define RTCP_SR_PACKET_TYPE 200 40 | #define RTCP_PACKET_SIZE 28 41 | 42 | #define NTP_OFFSET 2208988800ULL 43 | #define NTP_OFFSET_US (NTP_OFFSET * 1000000ULL) 44 | 45 | typedef struct 46 | { 47 | hnd_t udp_handle; 48 | 49 | uint16_t seq; 50 | uint32_t ssrc; 51 | 52 | uint32_t pkt_cnt; 53 | uint32_t octet_cnt; 54 | } obe_rtp_ctx; 55 | 56 | struct ip_status 57 | { 58 | obe_output_t *output; 59 | hnd_t *ip_handle; 60 | }; 61 | 62 | static int rtp_open( hnd_t *p_handle, obe_udp_opts_t *udp_opts ) 63 | { 64 | obe_rtp_ctx *p_rtp = calloc( 1, sizeof(*p_rtp) ); 65 | if( !p_rtp ) 66 | { 67 | fprintf( stderr, "[rtp] malloc failed" ); 68 | return -1; 69 | } 70 | 71 | if( udp_open( &p_rtp->udp_handle, udp_opts ) < 0 ) 72 | { 73 | fprintf( stderr, "[rtp] Could not create udp output" ); 74 | return -1; 75 | } 76 | 77 | p_rtp->ssrc = av_get_random_seed(); 78 | 79 | *p_handle = p_rtp; 80 | 81 | return 0; 82 | } 83 | #if 0 84 | static int64_t obe_gettime(void) 85 | { 86 | struct timeval tv; 87 | gettimeofday(&tv,NULL); 88 | return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec; 89 | } 90 | 91 | static uint64_t obe_ntp_time(void) 92 | { 93 | return (obe_gettime() / 1000) * 1000 + NTP_OFFSET_US; 94 | } 95 | 96 | static int write_rtcp_pkt( hnd_t handle ) 97 | { 98 | obe_rtp_ctx *p_rtp = handle; 99 | uint64_t ntp_time = obe_ntp_time(); 100 | uint8_t pkt[100]; 101 | bs_t s; 102 | bs_init( &s, pkt, RTCP_PACKET_SIZE ); 103 | 104 | bs_write( &s, 2, RTP_VERSION ); // version 105 | bs_write1( &s, 0 ); // padding 106 | bs_write( &s, 5, 0 ); // reception report count 107 | bs_write( &s, 8, RTCP_SR_PACKET_TYPE ); // packet type 108 | bs_write( &s, 8, 6 ); // length (length in words - 1) 109 | bs_write32( &s, p_rtp->ssrc ); // ssrc 110 | bs_write32( &s, ntp_time / 1000000 ); // NTP timestamp, most significant word 111 | bs_write32( &s, ((ntp_time % 1000000) << 32) / 1000000 ); // NTP timestamp, least significant word 112 | bs_write32( &s, 0 ); // RTP timestamp FIXME 113 | bs_write32( &s, p_rtp->pkt_cnt ); // sender's packet count 114 | bs_write32( &s, p_rtp->octet_cnt ); // sender's octet count 115 | bs_flush( &s ); 116 | 117 | if( udp_write( p_rtp->udp_handle, pkt, RTCP_PACKET_SIZE ) < 0 ) 118 | return -1; 119 | 120 | return 0; 121 | } 122 | #endif 123 | static int write_rtp_pkt( hnd_t handle, uint8_t *data, int len, int64_t timestamp ) 124 | { 125 | obe_rtp_ctx *p_rtp = handle; 126 | uint8_t pkt[RTP_HEADER_SIZE+TS_PACKETS_SIZE]; 127 | bs_t s; 128 | bs_init( &s, pkt, RTP_HEADER_SIZE+TS_PACKETS_SIZE ); 129 | 130 | bs_write( &s, 2, RTP_VERSION ); // version 131 | bs_write1( &s, 0 ); // padding 132 | bs_write1( &s, 0 ); // extension 133 | bs_write( &s, 4, 0 ); // CSRC count 134 | bs_write1( &s, 0 ); // marker 135 | bs_write( &s, 7, MPEG_TS_PAYLOAD_TYPE ); // payload type 136 | bs_write( &s, 16, p_rtp->seq++ ); // sequence number 137 | bs_write32( &s, timestamp / 300 ); // timestamp 138 | bs_write32( &s, p_rtp->ssrc ); // ssrc 139 | bs_flush( &s ); 140 | 141 | memcpy( &pkt[RTP_HEADER_SIZE], data, len ); 142 | 143 | if( udp_write( p_rtp->udp_handle, pkt, RTP_HEADER_SIZE+TS_PACKETS_SIZE ) < 0 ) 144 | return -1; 145 | 146 | p_rtp->pkt_cnt++; 147 | p_rtp->octet_cnt += len; 148 | 149 | return 0; 150 | } 151 | 152 | static void rtp_close( hnd_t handle ) 153 | { 154 | obe_rtp_ctx *p_rtp = handle; 155 | 156 | udp_close( p_rtp->udp_handle ); 157 | free( p_rtp ); 158 | } 159 | 160 | static void close_output( void *handle ) 161 | { 162 | struct ip_status *status = handle; 163 | 164 | if( status->output->output_dest.type == OUTPUT_RTP ) 165 | { 166 | if( *status->ip_handle ) 167 | rtp_close( *status->ip_handle ); 168 | } 169 | else 170 | { 171 | if( *status->ip_handle ) 172 | udp_close( *status->ip_handle ); 173 | } 174 | if( status->output->output_dest.target ) 175 | free( status->output->output_dest.target ); 176 | 177 | pthread_mutex_unlock( &status->output->queue.mutex ); 178 | } 179 | 180 | static void *open_output( void *ptr ) 181 | { 182 | obe_output_t *output = ptr; 183 | obe_output_dest_t *output_dest = &output->output_dest; 184 | struct ip_status status; 185 | hnd_t ip_handle = NULL; 186 | int num_muxed_data = 0; 187 | AVBufferRef **muxed_data; 188 | obe_udp_opts_t udp_opts; 189 | 190 | struct sched_param param = {0}; 191 | param.sched_priority = 99; 192 | pthread_setschedparam( pthread_self(), SCHED_FIFO, ¶m ); 193 | 194 | status.output = output; 195 | status.ip_handle = &ip_handle; 196 | pthread_cleanup_push( close_output, (void*)&status ); 197 | 198 | udp_populate_opts( &udp_opts, output_dest->target ); 199 | 200 | if( output_dest->type == OUTPUT_RTP ) 201 | { 202 | if( rtp_open( &ip_handle, &udp_opts ) < 0 ) 203 | return NULL; 204 | } 205 | else 206 | { 207 | if( udp_open( &ip_handle, &udp_opts ) < 0 ) 208 | { 209 | fprintf( stderr, "[udp] Could not create udp output" ); 210 | return NULL; 211 | } 212 | } 213 | 214 | while( 1 ) 215 | { 216 | pthread_mutex_lock( &output->queue.mutex ); 217 | while( !output->queue.size && !output->cancel_thread ) 218 | { 219 | /* Often this cond_wait is not because of an underflow */ 220 | pthread_cond_wait( &output->queue.in_cv, &output->queue.mutex ); 221 | } 222 | 223 | if( output->cancel_thread ) 224 | { 225 | pthread_mutex_unlock( &output->queue.mutex ); 226 | break; 227 | } 228 | 229 | num_muxed_data = output->queue.size; 230 | 231 | muxed_data = malloc( num_muxed_data * sizeof(*muxed_data) ); 232 | if( !muxed_data ) 233 | { 234 | pthread_mutex_unlock( &output->queue.mutex ); 235 | syslog( LOG_ERR, "Malloc failed\n" ); 236 | return NULL; 237 | } 238 | memcpy( muxed_data, output->queue.queue, num_muxed_data * sizeof(*muxed_data) ); 239 | pthread_mutex_unlock( &output->queue.mutex ); 240 | 241 | // printf("\n START %i \n", num_muxed_data ); 242 | 243 | for( int i = 0; i < num_muxed_data; i++ ) 244 | { 245 | if( output_dest->type == OUTPUT_RTP ) 246 | { 247 | if( write_rtp_pkt( ip_handle, &muxed_data[i]->data[7*sizeof(int64_t)], TS_PACKETS_SIZE, AV_RN64( muxed_data[i]->data ) ) < 0 ) 248 | syslog( LOG_ERR, "[rtp] Failed to write RTP packet\n" ); 249 | } 250 | else 251 | { 252 | if( udp_write( ip_handle, &muxed_data[i]->data[7*sizeof(int64_t)], TS_PACKETS_SIZE ) < 0 ) 253 | syslog( LOG_ERR, "[udp] Failed to write UDP packet\n" ); 254 | } 255 | 256 | remove_from_queue( &output->queue ); 257 | av_buffer_unref( &muxed_data[i] ); 258 | } 259 | 260 | free( muxed_data ); 261 | muxed_data = NULL; 262 | } 263 | 264 | pthread_cleanup_pop( 1 ); 265 | 266 | return NULL; 267 | } 268 | 269 | const obe_output_func_t ip_output = { open_output }; 270 | -------------------------------------------------------------------------------- /common/bitstream.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * bitstream.h: bitstream writing 3 | ***************************************************************************** 4 | * Copyright (C) 2003-2010 x264 project 5 | * 6 | * Authors: Loren Merritt 7 | * Jason Garrett-Glaser 8 | * Laurent Aimar 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 23 | * 24 | *****************************************************************************/ 25 | 26 | #ifndef OBE_BS_H 27 | #define OBE_BS_H 28 | 29 | #define WORD_SIZE sizeof(long) 30 | 31 | /* Unions for type-punning. 32 | * Mn: load or store n bits, aligned, native-endian 33 | * CPn: copy n bits, aligned, native-endian 34 | * we don't use memcpy for CPn because memcpy's args aren't assumed to be aligned */ 35 | typedef union { uint16_t i; uint8_t c[2]; } x264_union16_t; 36 | typedef union { uint32_t i; uint16_t b[2]; uint8_t c[4]; } x264_union32_t; 37 | typedef union { uint64_t i; uint32_t a[2]; uint16_t b[4]; uint8_t c[8]; } x264_union64_t; 38 | typedef struct { uint64_t i[2]; } x264_uint128_t; 39 | typedef union { x264_uint128_t i; uint64_t a[2]; uint32_t b[4]; uint16_t c[8]; uint8_t d[16]; } x264_union128_t; 40 | #define M16(src) (((x264_union16_t*)(src))->i) 41 | #define M32(src) (((x264_union32_t*)(src))->i) 42 | #define M64(src) (((x264_union64_t*)(src))->i) 43 | #define M128(src) (((x264_union128_t*)(src))->i) 44 | #define M128_ZERO ((x264_uint128_t){{0,0}}) 45 | #define CP16(dst,src) M16(dst) = M16(src) 46 | #define CP32(dst,src) M32(dst) = M32(src) 47 | #define CP64(dst,src) M64(dst) = M64(src) 48 | #define CP128(dst,src) M128(dst) = M128(src) 49 | 50 | #if WORDS_BIGENDIAN 51 | #define endian_fix(x) (x) 52 | #define endian_fix64(x) (x) 53 | #define endian_fix32(x) (x) 54 | #define endian_fix16(x) (x) 55 | #else 56 | static inline uint32_t endian_fix32( uint32_t x ) 57 | { 58 | return (x<<24) + ((x<<8)&0xff0000) + ((x>>8)&0xff00) + (x>>24); 59 | } 60 | static inline uint64_t endian_fix64( uint64_t x ) 61 | { 62 | return endian_fix32(x>>32) + ((uint64_t)endian_fix32(x)<<32); 63 | } 64 | static inline intptr_t endian_fix( intptr_t x ) 65 | { 66 | return WORD_SIZE == 8 ? endian_fix64(x) : endian_fix32(x); 67 | } 68 | static inline uint16_t endian_fix16( uint16_t x ) 69 | { 70 | return (x<<8)|(x>>8); 71 | } 72 | #endif 73 | 74 | typedef struct bs_s 75 | { 76 | uint8_t *p_start; 77 | uint8_t *p; 78 | uint8_t *p_end; 79 | 80 | intptr_t cur_bits; 81 | int i_left; /* i_count number of available bits */ 82 | } bs_t; 83 | 84 | static inline void bs_init( bs_t *s, void *p_data, int i_data ) 85 | { 86 | int offset = ((intptr_t)p_data & 3); 87 | s->p = s->p_start = (uint8_t*)p_data - offset; 88 | s->p_end = (uint8_t*)p_data + i_data; 89 | s->i_left = (WORD_SIZE - offset)*8; 90 | s->cur_bits = endian_fix32( M32(s->p) ); 91 | s->cur_bits >>= (4-offset)*8; 92 | } 93 | static inline int bs_pos( bs_t *s ) 94 | { 95 | return( 8 * (s->p - s->p_start) + (WORD_SIZE*8) - s->i_left ); 96 | } 97 | 98 | /* Write the rest of cur_bits to the bitstream; results in a bitstream no longer 32-bit aligned. */ 99 | static inline void bs_flush( bs_t *s ) 100 | { 101 | M32( s->p ) = endian_fix32( s->cur_bits << (s->i_left&31) ); 102 | s->p += WORD_SIZE - (s->i_left >> 3); 103 | s->i_left = WORD_SIZE*8; 104 | } 105 | /* The inverse of bs_flush: prepare the bitstream to be written to again. */ 106 | static inline void bs_realign( bs_t *s ) 107 | { 108 | int offset = ((intptr_t)s->p & 3); 109 | if( offset ) 110 | { 111 | s->p = (uint8_t*)s->p - offset; 112 | s->i_left = (WORD_SIZE - offset)*8; 113 | s->cur_bits = endian_fix32( M32(s->p) ); 114 | s->cur_bits >>= (4-offset)*8; 115 | } 116 | } 117 | 118 | static inline void bs_write( bs_t *s, int i_count, uint32_t i_bits ) 119 | { 120 | if( WORD_SIZE == 8 ) 121 | { 122 | s->cur_bits = (s->cur_bits << i_count) | i_bits; 123 | s->i_left -= i_count; 124 | if( s->i_left <= 32 ) 125 | { 126 | #if WORDS_BIGENDIAN 127 | M32( s->p ) = s->cur_bits >> (32 - s->i_left); 128 | #else 129 | M32( s->p ) = endian_fix( s->cur_bits << s->i_left ); 130 | #endif 131 | s->i_left += 32; 132 | s->p += 4; 133 | } 134 | } 135 | else 136 | { 137 | if( i_count < s->i_left ) 138 | { 139 | s->cur_bits = (s->cur_bits << i_count) | i_bits; 140 | s->i_left -= i_count; 141 | } 142 | else 143 | { 144 | i_count -= s->i_left; 145 | s->cur_bits = (s->cur_bits << s->i_left) | (i_bits >> i_count); 146 | M32( s->p ) = endian_fix( s->cur_bits ); 147 | s->p += 4; 148 | s->cur_bits = i_bits; 149 | s->i_left = 32 - i_count; 150 | } 151 | } 152 | } 153 | 154 | /* Special case to eliminate branch in normal bs_write. */ 155 | /* Golomb never writes an even-size code, so this is only used in slice headers. */ 156 | static inline void bs_write32( bs_t *s, uint32_t i_bits ) 157 | { 158 | bs_write( s, 16, i_bits >> 16 ); 159 | bs_write( s, 16, i_bits ); 160 | } 161 | 162 | static inline void bs_write1( bs_t *s, uint32_t i_bit ) 163 | { 164 | s->cur_bits <<= 1; 165 | s->cur_bits |= i_bit; 166 | s->i_left--; 167 | if( s->i_left == WORD_SIZE*8-32 ) 168 | { 169 | M32( s->p ) = endian_fix32( s->cur_bits ); 170 | s->p += 4; 171 | s->i_left = WORD_SIZE*8; 172 | } 173 | } 174 | 175 | static inline void bs_align_0( bs_t *s ) 176 | { 177 | bs_write( s, s->i_left&7, 0 ); 178 | bs_flush( s ); 179 | } 180 | static inline void bs_align_1( bs_t *s ) 181 | { 182 | bs_write( s, s->i_left&7, (1 << (s->i_left&7)) - 1 ); 183 | bs_flush( s ); 184 | } 185 | static inline void bs_align_10( bs_t *s ) 186 | { 187 | if( s->i_left&7 ) 188 | bs_write( s, s->i_left&7, 1 << ( (s->i_left&7) - 1 ) ); 189 | } 190 | 191 | /* golomb functions */ 192 | 193 | static const uint8_t x264_ue_size_tab[256] = 194 | { 195 | 1, 1, 3, 3, 5, 5, 5, 5, 7, 7, 7, 7, 7, 7, 7, 7, 196 | 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 197 | 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11, 198 | 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11, 199 | 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13, 200 | 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13, 201 | 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13, 202 | 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13, 203 | 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15, 204 | 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15, 205 | 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15, 206 | 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15, 207 | 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15, 208 | 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15, 209 | 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15, 210 | 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15, 211 | }; 212 | 213 | static inline void bs_write_ue_big( bs_t *s, unsigned int val ) 214 | { 215 | int size = 0; 216 | int tmp = ++val; 217 | if( tmp >= 0x10000 ) 218 | { 219 | size = 32; 220 | tmp >>= 16; 221 | } 222 | if( tmp >= 0x100 ) 223 | { 224 | size += 16; 225 | tmp >>= 8; 226 | } 227 | size += x264_ue_size_tab[tmp]; 228 | bs_write( s, size>>1, 0 ); 229 | bs_write( s, (size>>1)+1, val ); 230 | } 231 | 232 | /* Only works on values under 255. */ 233 | static inline void bs_write_ue( bs_t *s, int val ) 234 | { 235 | bs_write( s, x264_ue_size_tab[val+1], val+1 ); 236 | } 237 | 238 | static inline void bs_write_se( bs_t *s, int val ) 239 | { 240 | int size = 0; 241 | /* Faster than (val <= 0 ? -val*2+1 : val*2) */ 242 | /* 4 instructions on x86, 3 on ARM */ 243 | int tmp = 1 - val*2; 244 | if( tmp < 0 ) tmp = val*2; 245 | val = tmp; 246 | 247 | if( tmp >= 0x100 ) 248 | { 249 | size = 16; 250 | tmp >>= 8; 251 | } 252 | size += x264_ue_size_tab[tmp]; 253 | bs_write( s, size, val ); 254 | } 255 | 256 | static inline void bs_write_te( bs_t *s, int x, int val ) 257 | { 258 | if( x == 1 ) 259 | bs_write1( s, 1^val ); 260 | else //if( x > 1 ) 261 | bs_write_ue( s, val ); 262 | } 263 | 264 | static inline void bs_rbsp_trailing( bs_t *s ) 265 | { 266 | bs_write1( s, 1 ); 267 | bs_write( s, s->i_left&7, 0 ); 268 | } 269 | 270 | #endif 271 | -------------------------------------------------------------------------------- /input/sdi/linsys/include/sdivideo.h: -------------------------------------------------------------------------------- 1 | /* sdivideo.h 2 | * 3 | * Shared header file for the Linux user-space API for 4 | * Linear Systems Ltd. SMPTE 292M and SMPTE 259M-C interface boards. 5 | * 6 | * Copyright (C) 2009-2010 Linear Systems Ltd. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * 1. Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Linear Systems Ltd. nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY LINEAR SYSTEMS LTD. "AS IS" AND ANY 23 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL LINEAR SYSTEMS LTD. OR CONTRIBUTORS 26 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 27 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 29 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 31 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 32 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Linear Systems can be contacted at . 35 | * 36 | */ 37 | 38 | #ifndef _SDIVIDEO_H 39 | #define _SDIVIDEO_H 40 | 41 | /* Driver info */ 42 | #define SDIVIDEO_DRIVER_NAME "sdivideo" 43 | 44 | #define SDIVIDEO_MAJOR 0 /* Set to 0 for dynamic allocation. 45 | * See /usr/src/linux/Documentation/devices.txt */ 46 | 47 | #define SDIVIDEO_TX_BUFFERS_MIN 2 /* This must be at least 2 */ 48 | /* The minimum transmit buffer size must be positive, divisible by 4, 49 | * and large enough that the buffers aren't transferred to the onboard FIFOs 50 | * too quickly for the machine to handle the interrupts. 51 | * This is especially a problem at startup, when the FIFOs are empty. 52 | * Relevant factors include onboard FIFO size, PCI bus throughput, 53 | * processor speed, and interrupt latency. */ 54 | #define SDIVIDEO_TX_BUFSIZE_MIN 1024 55 | #define SDIVIDEO_RX_BUFFERS_MIN 2 /* This must be at least 2 */ 56 | #define SDIVIDEO_RX_BUFSIZE_MIN 8 /* This must be positive and divisible by 4 */ 57 | 58 | #define SDIVIDEO_TX_BUFFERS 30 /* This must be at least 2 */ 59 | #define SDIVIDEO_TX_BUFSIZE 1843200 /* This must be positive and divisible by 4 */ 60 | #define SDIVIDEO_RX_BUFFERS 30 /* This must be at least 2 */ 61 | #define SDIVIDEO_RX_BUFSIZE 1843200 /* This must be positive and divisible by 4 */ 62 | 63 | /* Ioctl () definitions */ 64 | #define SDIVIDEO_IOC_MAGIC '=' /* This ioctl magic number is currently free. See 65 | * /usr/src/linux/Documentation/ioctl-number.txt */ 66 | 67 | #define SDIVIDEO_IOC_TXGETCAP _IOR(SDIVIDEO_IOC_MAGIC, 1, unsigned int) 68 | #define SDIVIDEO_IOC_TXGETEVENTS _IOR(SDIVIDEO_IOC_MAGIC, 2, unsigned int) 69 | #define SDIVIDEO_IOC_TXGETBUFLEVEL _IOR(SDIVIDEO_IOC_MAGIC, 3, unsigned int) 70 | #define SDIVIDEO_IOC_TXGETTXD _IOR(SDIVIDEO_IOC_MAGIC, 4, int) 71 | #define SDIVIDEO_IOC_TXGETREF _IOR(SDIVIDEO_IOC_MAGIC, 5, unsigned int) 72 | 73 | #define SDIVIDEO_IOC_RXGETCAP _IOR(SDIVIDEO_IOC_MAGIC, 65, unsigned int) 74 | #define SDIVIDEO_IOC_RXGETEVENTS _IOR(SDIVIDEO_IOC_MAGIC, 66, unsigned int) 75 | #define SDIVIDEO_IOC_RXGETBUFLEVEL _IOR(SDIVIDEO_IOC_MAGIC, 67, unsigned int) 76 | #define SDIVIDEO_IOC_RXGETCARRIER _IOR(SDIVIDEO_IOC_MAGIC, 68, int) 77 | #define SDIVIDEO_IOC_RXGETSTATUS _IOR(SDIVIDEO_IOC_MAGIC, 69, int) 78 | #define SDIVIDEO_IOC_RXGETYCRCERROR _IOR(SDIVIDEO_IOC_MAGIC, 70, unsigned int) 79 | #define SDIVIDEO_IOC_RXGETCCRCERROR _IOR(SDIVIDEO_IOC_MAGIC, 71, unsigned int) 80 | #define SDIVIDEO_IOC_RXGETVIDSTATUS _IOR(SDIVIDEO_IOC_MAGIC, 72, unsigned int) 81 | 82 | #define SDIVIDEO_IOC_GETID _IOR(SDIVIDEO_IOC_MAGIC, 129, unsigned int) 83 | #define SDIVIDEO_IOC_GETVERSION _IOR(SDIVIDEO_IOC_MAGIC, 130, unsigned int) 84 | /* Provide compatibility with applications compiled for older API */ 85 | #define SDIVIDEO_IOC_QBUF_DEPRECATED _IOW(SDIVIDEO_IOC_MAGIC, 131, unsigned int) 86 | #define SDIVIDEO_IOC_QBUF _IO(SDIVIDEO_IOC_MAGIC, 131) 87 | /* Provide compatibility with applications compiled for older API */ 88 | #define SDIVIDEO_IOC_DQBUF_DEPRECATED _IOW(SDIVIDEO_IOC_MAGIC, 132, unsigned int) 89 | #define SDIVIDEO_IOC_DQBUF _IO(SDIVIDEO_IOC_MAGIC, 132) 90 | 91 | /* Transmitter event flag bit locations */ 92 | #define SDIVIDEO_EVENT_TX_BUFFER_ORDER 0 93 | #define SDIVIDEO_EVENT_TX_BUFFER (1 << SDIVIDEO_EVENT_TX_BUFFER_ORDER) 94 | #define SDIVIDEO_EVENT_TX_FIFO_ORDER 1 95 | #define SDIVIDEO_EVENT_TX_FIFO (1 << SDIVIDEO_EVENT_TX_FIFO_ORDER) 96 | #define SDIVIDEO_EVENT_TX_DATA_ORDER 2 97 | #define SDIVIDEO_EVENT_TX_DATA (1 << SDIVIDEO_EVENT_TX_DATA_ORDER) 98 | #define SDIVIDEO_EVENT_TX_REF_ORDER 3 99 | #define SDIVIDEO_EVENT_TX_REF (1 << SDIVIDEO_EVENT_TX_REF_ORDER) 100 | 101 | /* Receiver event flag bit locations */ 102 | #define SDIVIDEO_EVENT_RX_BUFFER_ORDER 0 103 | #define SDIVIDEO_EVENT_RX_BUFFER (1 << SDIVIDEO_EVENT_RX_BUFFER_ORDER) 104 | #define SDIVIDEO_EVENT_RX_FIFO_ORDER 1 105 | #define SDIVIDEO_EVENT_RX_FIFO (1 << SDIVIDEO_EVENT_RX_FIFO_ORDER) 106 | #define SDIVIDEO_EVENT_RX_CARRIER_ORDER 2 107 | #define SDIVIDEO_EVENT_RX_CARRIER (1 << SDIVIDEO_EVENT_RX_CARRIER_ORDER) 108 | #define SDIVIDEO_EVENT_RX_DATA_ORDER 3 109 | #define SDIVIDEO_EVENT_RX_DATA (1 << SDIVIDEO_EVENT_RX_DATA_ORDER) 110 | #define SDIVIDEO_EVENT_RX_STD_ORDER 4 111 | #define SDIVIDEO_EVENT_RX_STD (1 << SDIVIDEO_EVENT_RX_STD_ORDER) 112 | 113 | /* Interface capabilities */ 114 | #define SDIVIDEO_CAP_TX_VANC 0x00000040 115 | 116 | #define SDIVIDEO_CAP_RX_CD 0x00000001 117 | #define SDIVIDEO_CAP_RX_DATA 0x00000002 118 | #define SDIVIDEO_CAP_RX_ERR_COUNT 0x00000004 119 | #define SDIVIDEO_CAP_RX_VBI 0x00000008 120 | #define SDIVIDEO_CAP_RX_RAWMODE 0x00000010 121 | #define SDIVIDEO_CAP_RX_DEINTERLACING 0x00000020 122 | #define SDIVIDEO_CAP_RX_VANC 0x00000040 123 | 124 | /* Transmitter clock source settings */ 125 | #define SDIVIDEO_CTL_TX_CLKSRC_ONBOARD 0 126 | #define SDIVIDEO_CTL_TX_CLKSRC_NTSC 1 127 | #define SDIVIDEO_CTL_TX_CLKSRC_PAL 2 128 | #define SDIVIDEO_CTL_TX_CLKSRC_525P 3 129 | #define SDIVIDEO_CTL_TX_CLKSRC_625P 4 130 | #define SDIVIDEO_CTL_TX_CLKSRC_720P_60 5 131 | #define SDIVIDEO_CTL_TX_CLKSRC_720P_59_94 6 132 | #define SDIVIDEO_CTL_TX_CLKSRC_720P_50 7 133 | #define SDIVIDEO_CTL_TX_CLKSRC_720P_30 8 134 | #define SDIVIDEO_CTL_TX_CLKSRC_720P_29_97 9 135 | #define SDIVIDEO_CTL_TX_CLKSRC_720P_25 10 136 | #define SDIVIDEO_CTL_TX_CLKSRC_720P_24 11 137 | #define SDIVIDEO_CTL_TX_CLKSRC_720P_23_98 12 138 | #define SDIVIDEO_CTL_TX_CLKSRC_1080P_60 13 139 | #define SDIVIDEO_CTL_TX_CLKSRC_1080P_59_94 14 140 | #define SDIVIDEO_CTL_TX_CLKSRC_1080P_50 15 141 | #define SDIVIDEO_CTL_TX_CLKSRC_1080P_30 16 142 | #define SDIVIDEO_CTL_TX_CLKSRC_1080P_29_97 17 143 | #define SDIVIDEO_CTL_TX_CLKSRC_1080P_25 18 144 | #define SDIVIDEO_CTL_TX_CLKSRC_1080P_24 19 145 | #define SDIVIDEO_CTL_TX_CLKSRC_1080P_23_98 20 146 | #define SDIVIDEO_CTL_TX_CLKSRC_1080I_60 21 147 | #define SDIVIDEO_CTL_TX_CLKSRC_1080I_59_94 22 148 | #define SDIVIDEO_CTL_TX_CLKSRC_1080I_50 23 149 | 150 | /* Mode settings */ 151 | #define SDIVIDEO_CTL_MODE_UYVY 0 152 | #define SDIVIDEO_CTL_MODE_V210 1 153 | #define SDIVIDEO_CTL_MODE_V210_DEINTERLACE 2 154 | #define SDIVIDEO_CTL_MODE_RAW 3 155 | 156 | /* Frame mode settings */ 157 | #define SDIVIDEO_CTL_UNLOCKED 0 158 | #define SDIVIDEO_CTL_SMPTE_125M_486I_59_94HZ 1 159 | #define SDIVIDEO_CTL_BT_601_576I_50HZ 2 160 | #define SDIVIDEO_CTL_SMPTE_260M_1035I_60HZ 5 161 | #define SDIVIDEO_CTL_SMPTE_260M_1035I_59_94HZ 6 162 | #define SDIVIDEO_CTL_SMPTE_295M_1080I_50HZ 7 163 | #define SDIVIDEO_CTL_SMPTE_274M_1080I_60HZ 8 164 | #define SDIVIDEO_CTL_SMPTE_274M_1080PSF_30HZ 9 165 | #define SDIVIDEO_CTL_SMPTE_274M_1080I_59_94HZ 10 166 | #define SDIVIDEO_CTL_SMPTE_274M_1080PSF_29_97HZ 11 167 | #define SDIVIDEO_CTL_SMPTE_274M_1080I_50HZ 12 168 | #define SDIVIDEO_CTL_SMPTE_274M_1080PSF_25HZ 13 169 | #define SDIVIDEO_CTL_SMPTE_274M_1080PSF_24HZ 14 170 | #define SDIVIDEO_CTL_SMPTE_274M_1080PSF_23_98HZ 15 171 | #define SDIVIDEO_CTL_SMPTE_274M_1080P_30HZ 16 172 | #define SDIVIDEO_CTL_SMPTE_274M_1080P_29_97HZ 17 173 | #define SDIVIDEO_CTL_SMPTE_274M_1080P_25HZ 18 174 | #define SDIVIDEO_CTL_SMPTE_274M_1080P_24HZ 19 175 | #define SDIVIDEO_CTL_SMPTE_274M_1080P_23_98HZ 20 176 | #define SDIVIDEO_CTL_SMPTE_296M_720P_60HZ 21 177 | #define SDIVIDEO_CTL_SMPTE_296M_720P_59_94HZ 22 178 | #define SDIVIDEO_CTL_SMPTE_296M_720P_50HZ 23 179 | #define SDIVIDEO_CTL_SMPTE_296M_720P_30HZ 24 180 | #define SDIVIDEO_CTL_SMPTE_296M_720P_29_97HZ 25 181 | #define SDIVIDEO_CTL_SMPTE_296M_720P_25HZ 26 182 | #define SDIVIDEO_CTL_SMPTE_296M_720P_24HZ 27 183 | #define SDIVIDEO_CTL_SMPTE_296M_720P_23_98HZ 28 184 | 185 | #endif 186 | 187 | -------------------------------------------------------------------------------- /input/sdi/decklink/include/DeckLinkAPIConfiguration.h: -------------------------------------------------------------------------------- 1 | /* -LICENSE-START- 2 | ** Copyright (c) 2013 Blackmagic Design 3 | ** 4 | ** Permission is hereby granted, free of charge, to any person or organization 5 | ** obtaining a copy of the software and accompanying documentation covered by 6 | ** this license (the "Software") to use, reproduce, display, distribute, 7 | ** execute, and transmit the Software, and to prepare derivative works of the 8 | ** Software, and to permit third-parties to whom the Software is furnished to 9 | ** do so, all subject to the following: 10 | ** 11 | ** The copyright notices in the Software and this entire statement, including 12 | ** the above license grant, this restriction and the following disclaimer, 13 | ** must be included in all copies of the Software, in whole or in part, and 14 | ** all derivative works of the Software, unless such copies or derivative 15 | ** works are solely in the form of machine-executable object code generated by 16 | ** a source language processor. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | ** FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 21 | ** SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 22 | ** FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 23 | ** ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 24 | ** DEALINGS IN THE SOFTWARE. 25 | ** -LICENSE-END- 26 | */ 27 | 28 | #ifndef BMD_DECKLINKAPICONFIGURATION_H 29 | #define BMD_DECKLINKAPICONFIGURATION_H 30 | 31 | 32 | #ifndef BMD_CONST 33 | #if defined(_MSC_VER) 34 | #define BMD_CONST __declspec(selectany) static const 35 | #else 36 | #define BMD_CONST static const 37 | #endif 38 | #endif 39 | 40 | // Type Declarations 41 | 42 | 43 | // Interface ID Declarations 44 | 45 | BMD_CONST REFIID IID_IDeckLinkConfiguration = /* C679A35B-610C-4D09-B748-1D0478100FC0 */ {0xC6,0x79,0xA3,0x5B,0x61,0x0C,0x4D,0x09,0xB7,0x48,0x1D,0x04,0x78,0x10,0x0F,0xC0}; 46 | 47 | /* Enum BMDDeckLinkConfigurationID - DeckLink Configuration ID */ 48 | 49 | typedef uint32_t BMDDeckLinkConfigurationID; 50 | enum _BMDDeckLinkConfigurationID { 51 | 52 | /* Serial port Flags */ 53 | 54 | bmdDeckLinkConfigSwapSerialRxTx = /* 'ssrt' */ 0x73737274, 55 | 56 | /* Video Input/Output Flags */ 57 | 58 | bmdDeckLinkConfigUse1080pNotPsF = /* 'fpro' */ 0x6670726F, 59 | 60 | /* Video Input/Output Integers */ 61 | 62 | bmdDeckLinkConfigHDMI3DPackingFormat = /* '3dpf' */ 0x33647066, 63 | bmdDeckLinkConfigBypass = /* 'byps' */ 0x62797073, 64 | bmdDeckLinkConfigClockTimingAdjustment = /* 'ctad' */ 0x63746164, 65 | 66 | /* Audio Input/Output Flags */ 67 | 68 | bmdDeckLinkConfigAnalogAudioConsumerLevels = /* 'aacl' */ 0x6161636C, 69 | 70 | /* Video output flags */ 71 | 72 | bmdDeckLinkConfigFieldFlickerRemoval = /* 'fdfr' */ 0x66646672, 73 | bmdDeckLinkConfigHD1080p24ToHD1080i5994Conversion = /* 'to59' */ 0x746F3539, 74 | bmdDeckLinkConfig444SDIVideoOutput = /* '444o' */ 0x3434346F, 75 | bmdDeckLinkConfig3GBpsVideoOutput = /* '3gbs' */ 0x33676273, 76 | bmdDeckLinkConfigBlackVideoOutputDuringCapture = /* 'bvoc' */ 0x62766F63, 77 | bmdDeckLinkConfigLowLatencyVideoOutput = /* 'llvo' */ 0x6C6C766F, 78 | 79 | /* Video Output Integers */ 80 | 81 | bmdDeckLinkConfigVideoOutputConnection = /* 'vocn' */ 0x766F636E, 82 | bmdDeckLinkConfigVideoOutputConversionMode = /* 'vocm' */ 0x766F636D, 83 | bmdDeckLinkConfigAnalogVideoOutputFlags = /* 'avof' */ 0x61766F66, 84 | bmdDeckLinkConfigReferenceInputTimingOffset = /* 'glot' */ 0x676C6F74, 85 | bmdDeckLinkConfigVideoOutputIdleOperation = /* 'voio' */ 0x766F696F, 86 | bmdDeckLinkConfigDefaultVideoOutputMode = /* 'dvom' */ 0x64766F6D, 87 | bmdDeckLinkConfigDefaultVideoOutputModeFlags = /* 'dvof' */ 0x64766F66, 88 | 89 | /* Video Output Floats */ 90 | 91 | bmdDeckLinkConfigVideoOutputComponentLumaGain = /* 'oclg' */ 0x6F636C67, 92 | bmdDeckLinkConfigVideoOutputComponentChromaBlueGain = /* 'occb' */ 0x6F636362, 93 | bmdDeckLinkConfigVideoOutputComponentChromaRedGain = /* 'occr' */ 0x6F636372, 94 | bmdDeckLinkConfigVideoOutputCompositeLumaGain = /* 'oilg' */ 0x6F696C67, 95 | bmdDeckLinkConfigVideoOutputCompositeChromaGain = /* 'oicg' */ 0x6F696367, 96 | bmdDeckLinkConfigVideoOutputSVideoLumaGain = /* 'oslg' */ 0x6F736C67, 97 | bmdDeckLinkConfigVideoOutputSVideoChromaGain = /* 'oscg' */ 0x6F736367, 98 | 99 | /* Video Input Flags */ 100 | 101 | bmdDeckLinkConfigVideoInputScanning = /* 'visc' */ 0x76697363, // Applicable to H264 Pro Recorder only 102 | bmdDeckLinkConfigUseDedicatedLTCInput = /* 'dltc' */ 0x646C7463, // Use timecode from LTC input instead of SDI stream 103 | 104 | /* Video Input Integers */ 105 | 106 | bmdDeckLinkConfigVideoInputConnection = /* 'vicn' */ 0x7669636E, 107 | bmdDeckLinkConfigAnalogVideoInputFlags = /* 'avif' */ 0x61766966, 108 | bmdDeckLinkConfigVideoInputConversionMode = /* 'vicm' */ 0x7669636D, 109 | bmdDeckLinkConfig32PulldownSequenceInitialTimecodeFrame = /* 'pdif' */ 0x70646966, 110 | bmdDeckLinkConfigVANCSourceLine1Mapping = /* 'vsl1' */ 0x76736C31, 111 | bmdDeckLinkConfigVANCSourceLine2Mapping = /* 'vsl2' */ 0x76736C32, 112 | bmdDeckLinkConfigVANCSourceLine3Mapping = /* 'vsl3' */ 0x76736C33, 113 | 114 | /* Video Input Floats */ 115 | 116 | bmdDeckLinkConfigVideoInputComponentLumaGain = /* 'iclg' */ 0x69636C67, 117 | bmdDeckLinkConfigVideoInputComponentChromaBlueGain = /* 'iccb' */ 0x69636362, 118 | bmdDeckLinkConfigVideoInputComponentChromaRedGain = /* 'iccr' */ 0x69636372, 119 | bmdDeckLinkConfigVideoInputCompositeLumaGain = /* 'iilg' */ 0x69696C67, 120 | bmdDeckLinkConfigVideoInputCompositeChromaGain = /* 'iicg' */ 0x69696367, 121 | bmdDeckLinkConfigVideoInputSVideoLumaGain = /* 'islg' */ 0x69736C67, 122 | bmdDeckLinkConfigVideoInputSVideoChromaGain = /* 'iscg' */ 0x69736367, 123 | 124 | /* Audio Input Integers */ 125 | 126 | bmdDeckLinkConfigAudioInputConnection = /* 'aicn' */ 0x6169636E, 127 | 128 | /* Audio Input Floats */ 129 | 130 | bmdDeckLinkConfigAnalogAudioInputScaleChannel1 = /* 'ais1' */ 0x61697331, 131 | bmdDeckLinkConfigAnalogAudioInputScaleChannel2 = /* 'ais2' */ 0x61697332, 132 | bmdDeckLinkConfigAnalogAudioInputScaleChannel3 = /* 'ais3' */ 0x61697333, 133 | bmdDeckLinkConfigAnalogAudioInputScaleChannel4 = /* 'ais4' */ 0x61697334, 134 | bmdDeckLinkConfigDigitalAudioInputScale = /* 'dais' */ 0x64616973, 135 | 136 | /* Audio Output Integers */ 137 | 138 | bmdDeckLinkConfigAudioOutputAESAnalogSwitch = /* 'aoaa' */ 0x616F6161, 139 | 140 | /* Audio Output Floats */ 141 | 142 | bmdDeckLinkConfigAnalogAudioOutputScaleChannel1 = /* 'aos1' */ 0x616F7331, 143 | bmdDeckLinkConfigAnalogAudioOutputScaleChannel2 = /* 'aos2' */ 0x616F7332, 144 | bmdDeckLinkConfigAnalogAudioOutputScaleChannel3 = /* 'aos3' */ 0x616F7333, 145 | bmdDeckLinkConfigAnalogAudioOutputScaleChannel4 = /* 'aos4' */ 0x616F7334, 146 | bmdDeckLinkConfigDigitalAudioOutputScale = /* 'daos' */ 0x64616F73 147 | }; 148 | 149 | // Forward Declarations 150 | 151 | class IDeckLinkConfiguration; 152 | 153 | /* Interface IDeckLinkConfiguration - DeckLink Configuration interface */ 154 | 155 | class IDeckLinkConfiguration : public IUnknown 156 | { 157 | public: 158 | virtual HRESULT SetFlag (/* in */ BMDDeckLinkConfigurationID cfgID, /* in */ bool value) = 0; 159 | virtual HRESULT GetFlag (/* in */ BMDDeckLinkConfigurationID cfgID, /* out */ bool *value) = 0; 160 | virtual HRESULT SetInt (/* in */ BMDDeckLinkConfigurationID cfgID, /* in */ int64_t value) = 0; 161 | virtual HRESULT GetInt (/* in */ BMDDeckLinkConfigurationID cfgID, /* out */ int64_t *value) = 0; 162 | virtual HRESULT SetFloat (/* in */ BMDDeckLinkConfigurationID cfgID, /* in */ double value) = 0; 163 | virtual HRESULT GetFloat (/* in */ BMDDeckLinkConfigurationID cfgID, /* out */ double *value) = 0; 164 | virtual HRESULT SetString (/* in */ BMDDeckLinkConfigurationID cfgID, /* in */ const char *value) = 0; 165 | virtual HRESULT GetString (/* in */ BMDDeckLinkConfigurationID cfgID, /* out */ const char **value) = 0; 166 | virtual HRESULT WriteConfigurationToPreferences (void) = 0; 167 | 168 | protected: 169 | virtual ~IDeckLinkConfiguration () {}; // call Release method to drop reference count 170 | }; 171 | 172 | /* Functions */ 173 | 174 | extern "C" { 175 | 176 | 177 | }; 178 | 179 | 180 | #endif /* defined(BMD_DECKLINKAPICONFIGURATION_H) */ 181 | -------------------------------------------------------------------------------- /obecli.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * obecli.h : Open Broadcast Encoder CLI headers 3 | ***************************************************************************** 4 | * Copyright (C) 2010 Open Broadcast Systems Ltd. 5 | * 6 | * Authors: Kieran Kunhya 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | *****************************************************************************/ 23 | 24 | #ifndef OBECLI_H 25 | #define OBECLI_H 26 | 27 | void obe_cli_printf( const char *name, const char *fmt, ... ); 28 | 29 | #define RETURN_IF_ERR( cond, name, ret, ... )\ 30 | if( cond )\ 31 | {\ 32 | obe_cli_printf( name, __VA_ARGS__ ); \ 33 | return ret;\ 34 | } 35 | 36 | #define FAIL_IF_ERR( cond, name, ... ) RETURN_IF_ERR( cond, name, -1, __VA_ARGS__ ) 37 | 38 | typedef struct obecli_command_t obecli_command_t; 39 | 40 | static int add_stream( char *command, obecli_command_t *child ); 41 | static int remove_stream( char *command, obecli_command_t *child ); 42 | 43 | static int parse_command( char *command, obecli_command_t *commmand_list ); 44 | static int probe_device( char *command, obecli_command_t *child ); 45 | 46 | static int set_obe( char *command, obecli_command_t *child ); 47 | static int set_input( char *command, obecli_command_t *child ); 48 | static int set_stream( char *command, obecli_command_t *child ); 49 | static int set_muxer( char *command, obecli_command_t *child ); 50 | static int set_output( char *command, obecli_command_t *child ); 51 | static int set_outputs( char *command, obecli_command_t *child ); 52 | 53 | static int show_bitdepth( char *command, obecli_command_t *child ); 54 | static int show_decoders( char *command, obecli_command_t *child ); 55 | static int show_encoders( char *command, obecli_command_t *child ); 56 | static int show_help( char *command, obecli_command_t *child ); 57 | static int show_input( char *command, obecli_command_t *child ); 58 | static int show_inputs( char *command, obecli_command_t *child ); 59 | static int show_muxers( char *command, obecli_command_t *child ); 60 | static int show_output( char *command, obecli_command_t *child ); 61 | static int show_outputs( char *command, obecli_command_t *child ); 62 | 63 | static int show_input_streams( char *command, obecli_command_t *child ); 64 | static int show_output_streams( char *command, obecli_command_t *child ); 65 | 66 | static int start_encode( char *command, obecli_command_t *child ); 67 | static int stop_encode( char *command, obecli_command_t *child ); 68 | 69 | struct obecli_command_t 70 | { 71 | char *name; 72 | char *child_opts; 73 | char *description; 74 | int (*cmd_func)( char*, obecli_command_t* ); 75 | obecli_command_t *child_commands; 76 | }; 77 | 78 | typedef struct 79 | { 80 | int input; 81 | char *input_name; 82 | char *long_name; 83 | char *input_lib_name; 84 | } obecli_input_name_t; 85 | 86 | typedef struct 87 | { 88 | int format; 89 | char *format_name; 90 | char *long_name; 91 | char *decoder_name; 92 | char *encoder_name; 93 | } obecli_format_name_t; 94 | 95 | typedef struct 96 | { 97 | int muxer; 98 | char *muxer_name; 99 | char *long_name; 100 | char *mux_lib_name; 101 | } obecli_muxer_name_t; 102 | 103 | typedef struct 104 | { 105 | int output; 106 | char *output_name; 107 | char *long_name; 108 | char *output_lib_name; 109 | } obecli_output_name_t; 110 | 111 | /* Commands */ 112 | static obecli_command_t add_commands[] = 113 | { 114 | { "stream", "", "Add stream", add_stream, NULL }, 115 | { 0 } 116 | }; 117 | 118 | static obecli_command_t remove_commands[] = 119 | { 120 | { "stream", "", "Remove stream", remove_stream, NULL }, 121 | { 0 } 122 | }; 123 | 124 | static obecli_command_t show_commands[] = 125 | { 126 | { "bitdepth", "", "Show AVC encoder bit depth", show_bitdepth, NULL }, 127 | { "decoders", "", "Show supported decoders", show_decoders, NULL }, 128 | { "encoders", "", "Show supported encoders", show_encoders, NULL }, 129 | //{ "filters", "", "Show supported filters", show_filters, NULL }, 130 | { "input", "streams", "Show input streams", show_input, NULL }, 131 | { "inputs", "", "Show supported inputs", show_inputs, NULL }, 132 | { "muxers", "", "Show supported muxers", show_muxers, NULL }, 133 | { "output", "streams", "Show output streams", show_output, NULL }, 134 | { "outputs", "", "Show supported outputs", show_outputs, NULL }, 135 | { 0 } 136 | }; 137 | 138 | static obecli_command_t set_commands[] = 139 | { 140 | { "obe", "opts [opts]", "Set OBE options", set_obe, NULL }, 141 | { "input", "opts [opts]", "Set input options", set_input, NULL }, 142 | { "stream", "opts streamid:[opts]", "Set stream options", set_stream, NULL }, 143 | { "muxer", "[name] OR opts [opts]", "Set muxer name or muxer opts", set_muxer, NULL }, 144 | { "mux", "[name] OR opts [opts]", "Set muxer name or muxer opts", set_muxer, NULL }, 145 | { "output", "opts outputid:[opts]", "Set output name or output opts", set_output, NULL }, 146 | { "outputs", "[number]", "Set output name or output opts", set_outputs, NULL }, 147 | { 0 } 148 | }; 149 | 150 | static obecli_command_t main_commands[] = 151 | { 152 | { "add", "[item] ...", "Add stream", parse_command, add_commands }, 153 | { "help", "[item] ...", "Display help", show_help, NULL }, 154 | { "probe", "[input]", "Probe input", probe_device, NULL }, 155 | { "remove","[item] ...", "Remove stream", parse_command, remove_commands }, 156 | { "set", "[item] ...", "Set item", parse_command, set_commands }, 157 | { "show", "[item] ...", "Show item", parse_command, show_commands }, 158 | { "start", "", "Start encoding", start_encode, NULL }, 159 | { "stop", "", "Stop encoding", stop_encode, NULL }, 160 | { 0 } 161 | }; 162 | 163 | /* TODO: put this all in the main OBE library at some point */ 164 | /* Input Names */ 165 | static const obecli_input_name_t input_names[] = 166 | { 167 | { INPUT_URL, "URL", "URL (includes UDP and RTP)", "libavformat" }, 168 | { INPUT_DEVICE_DECKLINK, "Decklink", "Blackmagic Design Decklink input", "internal" }, 169 | { INPUT_DEVICE_DECKLINK, "Linsys SDI", "Linear Systems (DVEO) SDI card input", "internal" }, 170 | { 0, 0, 0 }, 171 | }; 172 | 173 | /* Format names */ 174 | static const obecli_format_name_t format_names[] = 175 | { 176 | { VIDEO_UNCOMPRESSED, "RAW", "Uncompressed Video", "N/A", "N/A" }, 177 | { VIDEO_AVC, "AVC", "Advanced Video Coding", "FFmpeg AVC decoder", "x264 encoder" }, 178 | { VIDEO_MPEG2, "MPEG-2", "MPEG-2 Video", "FFmpeg MPEG-2 decoder", "N/A" }, 179 | { AUDIO_PCM, "PCM", "PCM (raw audio)", "N/A", "N/A" }, 180 | { AUDIO_MP2, "MP2", "MPEG-1 Layer II Audio", "FFmpeg MP2 audio decoder", "twolame encoder" }, 181 | { AUDIO_AC_3, "AC3", "ATSC A/52B / AC-3", "FFmpeg AC-3 audio decoder", "FFmpeg AC-3 encoder" }, 182 | { AUDIO_E_AC_3, "E-AC3", "ATSC A/52B Annex E / Enhanced AC-3", "FFmpeg E-AC3 audio decoder", "FFmpeg E-AC3 encoder" }, 183 | // { AUDIO_E_DIST, "E-Dist", "E-distribution audio" }, 184 | { AUDIO_AAC, "AAC", "Advanced Audio Coding", "FFmpeg AAC decoder", "FFmpeg AAC encoder" }, 185 | { SUBTITLES_DVB, "DVB-SUB", "DVB Subtitles", "N/A", "N/A" }, 186 | { MISC_TELETEXT, "DVB-TTX", "DVB Teletext", "N/A", "N/A" }, 187 | { MISC_WSS, "WSS", "Wide Screen Signalling", "N/A", "N/A" }, 188 | { MISC_VPS, "VPS", "Video Programming System", "N/A", "N/A" }, 189 | { CAPTIONS_CEA_608, "CEA-608", "CEA-608 Captions", "N/A", "N/A" }, 190 | { CAPTIONS_CEA_708, "CEA-708", "CEA-708 Captions", "N/A", "N/A" }, 191 | { MISC_AFD, "AFD", "Active Format Description", "N/A", "N/A" }, 192 | { MISC_BAR_DATA, "BAR-DATA", "Bar Data", "N/A", "N/A" }, 193 | { MISC_PAN_SCAN, "PAN-SCAN", "Pan-Scan Data", "N/A", "N/A" }, 194 | { VBI_RAW, "VBI", "Vertical Blanking Information", "N/A", "N/A" }, 195 | { 0, 0, 0, 0, 0 }, 196 | }; 197 | 198 | /* Muxer names */ 199 | static const obecli_muxer_name_t muxer_names[] = 200 | { 201 | { MUXERS_MPEGTS, "MPEG-TS", "MPEG Transport Stream", "libmpegts" }, 202 | { 0, 0, 0, 0 }, 203 | }; 204 | 205 | /* Output names */ 206 | static const obecli_output_name_t output_names[] = 207 | { 208 | { OUTPUT_UDP, "UDP", "MPEG-TS in UDP", "internal" }, 209 | { OUTPUT_RTP, "RTP", "MPEG-TS in RTP in UDP", "internal" }, 210 | { 0, 0, 0, 0 }, 211 | }; 212 | #endif 213 | -------------------------------------------------------------------------------- /encoders/audio/lavc/lavc.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * lavc.c: libavcodec audio encoding functions 3 | ***************************************************************************** 4 | * Copyright (C) 2010 Open Broadcast Systems Ltd. 5 | * 6 | * Authors: Kieran Kunhya 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | ******************************************************************************/ 23 | 24 | #include "common/common.h" 25 | #include "common/lavc.h" 26 | #include "encoders/audio/audio.h" 27 | #include 28 | #include 29 | #include 30 | 31 | typedef struct 32 | { 33 | int obe_name; 34 | int lavc_name; 35 | } lavc_encoder_t; 36 | 37 | static const lavc_encoder_t lavc_encoders[] = 38 | { 39 | { AUDIO_AC_3, AV_CODEC_ID_AC3 }, 40 | { AUDIO_E_AC_3, AV_CODEC_ID_EAC3 }, 41 | { AUDIO_AAC, AV_CODEC_ID_AAC }, 42 | { -1, -1 }, 43 | }; 44 | 45 | static void *start_encoder( void *ptr ) 46 | { 47 | obe_aud_enc_params_t *enc_params = ptr; 48 | obe_t *h = enc_params->h; 49 | obe_encoder_t *encoder = enc_params->encoder; 50 | obe_output_stream_t *stream = enc_params->stream; 51 | obe_raw_frame_t *raw_frame; 52 | obe_coded_frame_t *coded_frame; 53 | int64_t cur_pts = -1, pts_increment; 54 | int i, frame_size, ret, got_pkt, num_frames = 0, total_size = 0; 55 | AVFifoBuffer *out_fifo = NULL; 56 | AVAudioResampleContext *avr = NULL; 57 | AVPacket pkt; 58 | AVCodecContext *codec = NULL; 59 | AVFrame *frame = NULL; 60 | AVDictionary *opts = NULL; 61 | char is_latm[2]; 62 | uint8_t *audio_planes[8] = { NULL }; 63 | 64 | avcodec_register_all(); 65 | 66 | codec = avcodec_alloc_context3( NULL ); 67 | if( !codec ) 68 | { 69 | fprintf( stderr, "Malloc failed\n" ); 70 | goto finish; 71 | } 72 | 73 | for( i = 0; lavc_encoders[i].obe_name != -1; i++ ) 74 | { 75 | if( lavc_encoders[i].obe_name == stream->stream_format ) 76 | break; 77 | } 78 | 79 | if( lavc_encoders[i].obe_name == -1 ) 80 | { 81 | fprintf( stderr, "[lavc] Could not find encoder1\n" ); 82 | goto finish; 83 | } 84 | 85 | AVCodec *enc = avcodec_find_encoder( lavc_encoders[i].lavc_name ); 86 | if( !enc ) 87 | { 88 | fprintf( stderr, "[lavc] Could not find encoder2\n" ); 89 | goto finish; 90 | } 91 | 92 | if( enc->sample_fmts[0] == -1 ) 93 | { 94 | fprintf( stderr, "[lavc] No valid sample formats\n" ); 95 | goto finish; 96 | } 97 | 98 | codec->sample_rate = enc_params->sample_rate; 99 | codec->bit_rate = stream->bitrate * 1000; 100 | codec->sample_fmt = enc->sample_fmts[0]; 101 | codec->channels = av_get_channel_layout_nb_channels( stream->channel_layout ); 102 | codec->channel_layout = stream->channel_layout; 103 | codec->time_base.num = 1; 104 | codec->time_base.den = OBE_CLOCK; 105 | codec->profile = stream->aac_opts.aac_profile == AAC_HE_V2 ? FF_PROFILE_AAC_HE_V2 : 106 | stream->aac_opts.aac_profile == AAC_HE_V1 ? FF_PROFILE_AAC_HE : 107 | FF_PROFILE_AAC_LOW; 108 | 109 | snprintf( is_latm, sizeof(is_latm), "%i", stream->aac_opts.latm_output ); 110 | av_dict_set( &opts, "latm", is_latm, 0 ); 111 | av_dict_set( &opts, "header_period", "2", 0 ); 112 | 113 | if( avcodec_open2( codec, enc, &opts ) < 0 ) 114 | { 115 | fprintf( stderr, "[lavc] Could not open encoder\n" ); 116 | goto finish; 117 | } 118 | 119 | avr = avresample_alloc_context(); 120 | if( !avr ) 121 | { 122 | fprintf( stderr, "Malloc failed\n" ); 123 | goto finish; 124 | } 125 | 126 | av_opt_set_int( avr, "in_channel_layout", codec->channel_layout, 0 ); 127 | av_opt_set_int( avr, "in_sample_fmt", enc_params->input_sample_format, 0 ); 128 | av_opt_set_int( avr, "in_sample_rate", enc_params->sample_rate, 0 ); 129 | av_opt_set_int( avr, "out_channel_layout", codec->channel_layout, 0 ); 130 | av_opt_set_int( avr, "out_sample_fmt", codec->sample_fmt, 0 ); 131 | av_opt_set_int( avr, "dither_method", AV_RESAMPLE_DITHER_TRIANGULAR_NS, 0 ); 132 | 133 | if( avresample_open( avr ) < 0 ) 134 | { 135 | fprintf( stderr, "Could not open AVResample\n" ); 136 | goto finish; 137 | } 138 | 139 | /* The number of samples per E-AC3 frame is unknown until the encoder is ready */ 140 | if( stream->stream_format == AUDIO_E_AC_3 || stream->stream_format == AUDIO_AAC ) 141 | { 142 | pthread_mutex_lock( &encoder->queue.mutex ); 143 | encoder->is_ready = 1; 144 | encoder->num_samples = codec->frame_size; 145 | /* Broadcast because input and muxer can be stuck waiting for encoder */ 146 | pthread_cond_broadcast( &encoder->queue.in_cv ); 147 | pthread_mutex_unlock( &encoder->queue.mutex ); 148 | } 149 | 150 | frame_size = (double)codec->frame_size * 125 * stream->bitrate * 151 | enc_params->frames_per_pes / enc_params->sample_rate; 152 | /* NB: libfdk-aac already doubles the frame size appropriately */ 153 | pts_increment = (double)codec->frame_size * OBE_CLOCK * enc_params->frames_per_pes / enc_params->sample_rate; 154 | 155 | out_fifo = av_fifo_alloc( frame_size ); 156 | if( !out_fifo ) 157 | { 158 | fprintf( stderr, "Malloc failed\n" ); 159 | goto finish; 160 | } 161 | 162 | frame = avcodec_alloc_frame(); 163 | if( !frame ) 164 | { 165 | fprintf( stderr, "Could not allocate frame\n" ); 166 | goto finish; 167 | } 168 | 169 | if( av_samples_alloc( audio_planes, NULL, codec->channels, codec->frame_size, codec->sample_fmt, 0 ) < 0 ) 170 | { 171 | fprintf( stderr, "Could not allocate audio samples\n" ); 172 | goto finish; 173 | } 174 | 175 | while( 1 ) 176 | { 177 | /* TODO: detect bitrate or channel reconfig */ 178 | pthread_mutex_lock( &encoder->queue.mutex ); 179 | 180 | while( !encoder->queue.size && !encoder->cancel_thread ) 181 | pthread_cond_wait( &encoder->queue.in_cv, &encoder->queue.mutex ); 182 | 183 | if( encoder->cancel_thread ) 184 | { 185 | pthread_mutex_unlock( &encoder->queue.mutex ); 186 | goto finish; 187 | } 188 | 189 | raw_frame = encoder->queue.queue[0]; 190 | pthread_mutex_unlock( &encoder->queue.mutex ); 191 | 192 | if( cur_pts == -1 ) 193 | cur_pts = raw_frame->pts; 194 | 195 | if( avresample_convert( avr, NULL, 0, raw_frame->audio_frame.num_samples, raw_frame->audio_frame.audio_data, 196 | raw_frame->audio_frame.linesize, raw_frame->audio_frame.num_samples ) < 0 ) 197 | { 198 | syslog( LOG_ERR, "[lavc] Sample format conversion failed\n" ); 199 | break; 200 | } 201 | 202 | raw_frame->release_data( raw_frame ); 203 | raw_frame->release_frame( raw_frame ); 204 | remove_from_queue( &encoder->queue ); 205 | 206 | while( avresample_available( avr ) >= codec->frame_size ) 207 | { 208 | got_pkt = 0; 209 | avcodec_get_frame_defaults( frame ); 210 | frame->nb_samples = codec->frame_size; 211 | memcpy( frame->data, audio_planes, sizeof(frame->data) ); 212 | avresample_read( avr, frame->data, codec->frame_size ); 213 | 214 | av_init_packet( &pkt ); 215 | pkt.data = NULL; 216 | pkt.size = 0; 217 | 218 | ret = avcodec_encode_audio2( codec, &pkt, frame, &got_pkt ); 219 | if( ret < 0 ) 220 | { 221 | syslog( LOG_ERR, "[lavc] Audio encoding failed\n" ); 222 | goto finish; 223 | } 224 | 225 | if( !got_pkt ) 226 | continue; 227 | 228 | total_size += pkt.size; 229 | num_frames++; 230 | 231 | if( av_fifo_realloc2( out_fifo, av_fifo_size( out_fifo ) + pkt.size ) < 0 ) 232 | { 233 | syslog( LOG_ERR, "Malloc failed\n" ); 234 | break; 235 | } 236 | 237 | av_fifo_generic_write( out_fifo, pkt.data, pkt.size, NULL ); 238 | obe_free_packet( &pkt ); 239 | 240 | if( num_frames == enc_params->frames_per_pes ) 241 | { 242 | coded_frame = new_coded_frame( encoder->output_stream_id, total_size ); 243 | if( !coded_frame ) 244 | { 245 | syslog( LOG_ERR, "Malloc failed\n" ); 246 | goto finish; 247 | } 248 | 249 | av_fifo_generic_read( out_fifo, coded_frame->data, total_size, NULL ); 250 | 251 | coded_frame->pts = cur_pts; 252 | coded_frame->random_access = 1; /* Every frame output is a random access point */ 253 | add_to_queue( &h->mux_queue, coded_frame ); 254 | 255 | /* We need to generate PTS because frame sizes have changed */ 256 | cur_pts += pts_increment; 257 | total_size = num_frames = 0; 258 | } 259 | } 260 | } 261 | 262 | finish: 263 | if( frame ) 264 | avcodec_free_frame( &frame ); 265 | 266 | if( audio_planes[0] ) 267 | av_free( audio_planes[0] ); 268 | 269 | if( out_fifo ) 270 | av_fifo_free( out_fifo ); 271 | 272 | if( avr ) 273 | avresample_free( &avr ); 274 | 275 | if( codec ) 276 | { 277 | avcodec_close( codec ); 278 | av_free( codec ); 279 | } 280 | 281 | free( enc_params ); 282 | 283 | return NULL; 284 | } 285 | 286 | const obe_aud_enc_func_t lavc_encoder = { start_encoder }; 287 | -------------------------------------------------------------------------------- /common/network/udp/udp.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * udp.c : UDP output functions 3 | ***************************************************************************** 4 | * Copyright (C) 2010 Open Broadcast Systems Ltd. 5 | * 6 | * Large Portions of this code originate from FFmpeg 7 | * Authors: Kieran Kunhya 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 22 | * 23 | *****************************************************************************/ 24 | 25 | #include "common/common.h" 26 | #include "common/network/network.h" 27 | #include "output/output.h" 28 | #include "udp.h" 29 | 30 | typedef struct 31 | { 32 | char hostname[1024]; 33 | int port; 34 | int ttl; 35 | int miface; 36 | int buffer_size; 37 | int reuse_socket; 38 | int is_connected; 39 | 40 | int udp_fd; 41 | int is_multicast; 42 | int local_port; 43 | struct sockaddr_storage dest_addr; 44 | int dest_addr_len; 45 | } obe_udp_ctx; 46 | 47 | static int udp_set_multicast_opts( int sockfd, obe_udp_ctx *s ) 48 | { 49 | struct sockaddr *addr = (struct sockaddr *)&s->dest_addr; 50 | 51 | if( addr->sa_family == AF_INET ) 52 | { 53 | #ifdef IP_MULTICAST_TTL 54 | if( setsockopt( sockfd, IPPROTO_IP, IP_MULTICAST_TTL, &s->ttl, sizeof(s->ttl) ) < 0 ) 55 | { 56 | fprintf( stderr, "[udp] Could not setup IPv4 multicast\n" ); 57 | return -1; 58 | } 59 | #endif 60 | 61 | #ifdef IP_MULTICAST_IF 62 | struct ip_mreqn req = { .imr_ifindex = s->miface }; 63 | if( setsockopt( sockfd, IPPROTO_IP, IP_MULTICAST_IF, &req, sizeof(req) ) < 0 ) 64 | { 65 | fprintf( stderr, "[udp] Could not setup multicast interface\n" ); 66 | return -1; 67 | } 68 | #endif 69 | } 70 | 71 | #ifdef IPPROTO_IPV6 72 | if( addr->sa_family == AF_INET6 ) 73 | { 74 | #ifdef IPV6_MULTICAST_HOPS 75 | if( setsockopt( sockfd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &s->ttl, sizeof(s->ttl) ) < 0 ) 76 | { 77 | fprintf( stderr, "[udp] Could not setup IPv6 multicast\n" ); 78 | return -1; 79 | } 80 | #endif 81 | #ifdef IPV6_MULTICAST_IF 82 | if( setsockopt( sockfd, IPPROTO_IPV6, IPV6_MULTICAST_IF, &s->miface, sizeof(s->miface) ) < 0 ) 83 | { 84 | fprintf( stderr, "[udp] Could not setup IPv6 multicast interface\n" ); 85 | return -1; 86 | } 87 | #endif 88 | } 89 | #endif 90 | return 0; 91 | } 92 | 93 | static struct addrinfo* udp_resolve_host( const char *hostname, int port, int type, int family, int flags ) 94 | { 95 | struct addrinfo hints, *res = 0; 96 | int error; 97 | char sport[16]; 98 | const char *node = 0, *service = "0"; 99 | 100 | if( port > 0 ) 101 | { 102 | snprintf( sport, sizeof(sport), "%d", port ); 103 | service = sport; 104 | } 105 | if( (hostname) && (hostname[0] != '\0') && (hostname[0] != '?') ) 106 | node = hostname; 107 | 108 | memset( &hints, 0, sizeof(hints) ); 109 | hints.ai_socktype = type; 110 | hints.ai_family = family; 111 | hints.ai_flags = flags; 112 | if( (error = getaddrinfo( node, service, &hints, &res )) ) 113 | { 114 | res = NULL; 115 | fprintf( stderr, "[udp] error: %s \n", gai_strerror( error ) ); 116 | } 117 | 118 | return res; 119 | } 120 | 121 | static int udp_set_url( struct sockaddr_storage *addr, const char *hostname, int port ) 122 | { 123 | struct addrinfo *res0; 124 | int addr_len; 125 | 126 | res0 = udp_resolve_host( hostname, port, SOCK_DGRAM, AF_UNSPEC, 0 ); 127 | if( res0 == 0 ) 128 | return -1; 129 | memcpy( addr, res0->ai_addr, res0->ai_addrlen ); 130 | addr_len = res0->ai_addrlen; 131 | freeaddrinfo( res0 ); 132 | 133 | return addr_len; 134 | } 135 | 136 | static int udp_socket_create( obe_udp_ctx *s, struct sockaddr_storage *addr, int *addr_len ) 137 | { 138 | int udp_fd = -1; 139 | struct addrinfo *res0 = NULL, *res = NULL; 140 | int family = AF_UNSPEC; 141 | 142 | if( ((struct sockaddr *) &s->dest_addr)->sa_family ) 143 | family = ((struct sockaddr *) &s->dest_addr)->sa_family; 144 | res0 = udp_resolve_host( 0, s->local_port, SOCK_DGRAM, family, AI_PASSIVE ); 145 | if( res0 == 0 ) 146 | goto fail; 147 | for( res = res0; res; res=res->ai_next ) 148 | { 149 | udp_fd = socket( res->ai_family, SOCK_DGRAM, 0 ); 150 | if( udp_fd > 0 ) 151 | break; 152 | // TODO error 153 | } 154 | 155 | if( udp_fd < 0 ) 156 | goto fail; 157 | 158 | memcpy( addr, res->ai_addr, res->ai_addrlen ); 159 | *addr_len = res->ai_addrlen; 160 | 161 | freeaddrinfo( res0 ); 162 | 163 | return udp_fd; 164 | 165 | fail: 166 | if( udp_fd >= 0 ) 167 | close( udp_fd ); 168 | if( res0 ) 169 | freeaddrinfo( res0 ); 170 | return -1; 171 | } 172 | 173 | static int udp_port( struct sockaddr_storage *addr, int addr_len ) 174 | { 175 | char sbuf[sizeof(int)*3+1]; 176 | 177 | if( getnameinfo( (struct sockaddr *)addr, addr_len, NULL, 0, sbuf, sizeof(sbuf), NI_NUMERICSERV ) != 0 ) 178 | { 179 | fprintf( stderr, "[udp]: getnameinfo failed \n" ); 180 | return -1; 181 | } 182 | 183 | return strtol( sbuf, NULL, 10 ); 184 | } 185 | 186 | /** 187 | * If no filename is given to av_open_input_file because you want to 188 | * get the local port first, then you must call this function to set 189 | * the remote server address. 190 | * 191 | * url syntax: udp://host:port[?option=val...] 192 | * option: 'ttl=n' : set the ttl value (for multicast only) 193 | * 'localport=n' : set the local port 194 | * 'pkt_size=n' : set max packet size 195 | * 'reuse=1' : enable reusing the socket 196 | * 197 | * @param h media file context 198 | * @param uri of the remote server 199 | * @return zero if no error. 200 | */ 201 | static int udp_set_remote_url( obe_udp_ctx *s ) 202 | { 203 | /* set the destination address */ 204 | s->dest_addr_len = udp_set_url( &s->dest_addr, s->hostname, s->port ); 205 | if( s->dest_addr_len < 0 ) 206 | return -1; 207 | 208 | s->is_multicast = is_multicast_address( (struct sockaddr*) &s->dest_addr ); 209 | 210 | return 0; 211 | } 212 | 213 | void udp_populate_opts( obe_udp_opts_t *udp_opts, char *uri ) 214 | { 215 | char buf[256]; 216 | const char *p = strchr( uri, '?' ); 217 | 218 | memset( udp_opts, 0, sizeof(*udp_opts) ); 219 | 220 | if( p ) 221 | { 222 | if( av_find_info_tag( buf, sizeof(buf), "reuse", p ) ) 223 | { 224 | const char *endptr = NULL; 225 | udp_opts->reuse_socket = strtol( buf, (char **)&endptr, 10 ); 226 | /* assume if no digits were found it is a request to enable it */ 227 | if( buf == endptr ) 228 | udp_opts->reuse_socket = 1; 229 | } 230 | if( av_find_info_tag( buf, sizeof(buf), "ttl", p ) ) 231 | udp_opts->ttl = strtol( buf, NULL, 10 ); 232 | 233 | if( av_find_info_tag( buf, sizeof(buf), "localport", p ) ) 234 | udp_opts->local_port = strtol( buf, NULL, 10 ); 235 | 236 | if( av_find_info_tag( buf, sizeof(buf), "buffer_size", p ) ) 237 | udp_opts->buffer_size = strtol( buf, NULL, 10 ); 238 | 239 | if( av_find_info_tag( buf, sizeof(buf), "miface", p ) ) 240 | udp_opts->miface = if_nametoindex( buf ); 241 | } 242 | 243 | /* fill the dest addr */ 244 | av_url_split( NULL, 0, NULL, 0, udp_opts->hostname, sizeof(udp_opts->hostname), &udp_opts->port, NULL, 0, uri ); 245 | } 246 | 247 | int udp_open( hnd_t *p_handle, obe_udp_opts_t *udp_opts ) 248 | { 249 | int udp_fd = -1, tmp, bind_ret = -1; 250 | struct sockaddr_storage my_addr; 251 | int len; 252 | 253 | obe_udp_ctx *s = calloc( 1, sizeof(*s) ); 254 | *p_handle = NULL; 255 | if( !s ) 256 | return -1; 257 | 258 | strncpy( s->hostname, udp_opts->hostname, sizeof(s->hostname) ); 259 | s->port = udp_opts->port; 260 | s->local_port = udp_opts->local_port; 261 | s->reuse_socket = udp_opts->reuse_socket; 262 | s->ttl = udp_opts->ttl; 263 | s->buffer_size = udp_opts->buffer_size; 264 | s->miface = udp_opts->miface; 265 | 266 | if( udp_set_remote_url( s ) < 0 ) 267 | goto fail; 268 | 269 | udp_fd = udp_socket_create( s, &my_addr, &len ); 270 | if( udp_fd < 0 ) 271 | goto fail; 272 | 273 | if( s->reuse_socket || s->is_multicast ) 274 | { 275 | s->reuse_socket = 1; 276 | if( setsockopt( udp_fd, SOL_SOCKET, SO_REUSEADDR, &(s->reuse_socket), sizeof(s->reuse_socket) ) != 0) 277 | goto fail; 278 | } 279 | 280 | /* bind to the local address if not multicast or if the multicast 281 | * bind failed */ 282 | if( bind_ret < 0 && bind( udp_fd, (struct sockaddr *)&my_addr, len ) < 0 ) 283 | goto fail; 284 | 285 | len = sizeof(my_addr); 286 | getsockname( udp_fd, (struct sockaddr *)&my_addr, (socklen_t *) &len ); 287 | s->local_port = udp_port( &my_addr, len ); 288 | 289 | /* set output multicast ttl */ 290 | if( s->is_multicast && udp_set_multicast_opts( udp_fd, s ) < 0 ) 291 | goto fail; 292 | 293 | /* limit the tx buf size to limit latency */ 294 | tmp = s->buffer_size; 295 | if( setsockopt( udp_fd, SOL_SOCKET, SO_SNDBUF, &tmp, sizeof(tmp) ) < 0 ) 296 | goto fail; 297 | 298 | if( s->is_connected && connect( udp_fd, (struct sockaddr *)&s->dest_addr, s->dest_addr_len ) ) 299 | goto fail; 300 | 301 | s->udp_fd = udp_fd; 302 | *p_handle = s; 303 | return 0; 304 | 305 | fail: 306 | if( udp_fd >= 0 ) 307 | close( udp_fd ); 308 | 309 | free( s ); 310 | return -1; 311 | } 312 | 313 | int udp_write( hnd_t handle, uint8_t *buf, int size ) 314 | { 315 | obe_udp_ctx *s = handle; 316 | int ret; 317 | 318 | if( !s->is_connected ) 319 | ret = sendto( s->udp_fd, buf, size, 0, (struct sockaddr *)&s->dest_addr, s->dest_addr_len ); 320 | else 321 | ret = send( s->udp_fd, buf, size, 0 ); 322 | 323 | if( ret < 0 ) 324 | { 325 | syslog( LOG_WARNING, "UDP packet failed to send \n" ); 326 | return -1; 327 | } 328 | 329 | return size; 330 | } 331 | 332 | void udp_close( hnd_t handle ) 333 | { 334 | obe_udp_ctx *s = handle; 335 | 336 | close( s->udp_fd ); 337 | free( s ); 338 | } 339 | -------------------------------------------------------------------------------- /common/linsys/asi.h: -------------------------------------------------------------------------------- 1 | /* asi.h 2 | * 3 | * Shared header file for the Linux user-space API for 4 | * Linear Systems Ltd. DVB Master ASI interface boards. 5 | * 6 | * Copyright (C) 1999 Tony Bolger 7 | * Copyright (C) 2000-2010 Linear Systems Ltd. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions are met: 11 | * 12 | * 1. Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * 3. Neither the name of Linear Systems Ltd. nor the names of its 20 | * contributors may be used to endorse or promote products derived from 21 | * this software without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY LINEAR SYSTEMS LTD. "AS IS" AND ANY 24 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | * ARE DISCLAIMED. IN NO EVENT SHALL LINEAR SYSTEMS LTD. OR CONTRIBUTORS 27 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 28 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 30 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 31 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 32 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 33 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | * Linear Systems can be contacted at . 36 | * 37 | */ 38 | 39 | #ifndef _ASI_H 40 | #define _ASI_H 41 | 42 | /* Driver info */ 43 | #define ASI_DRIVER_NAME "asi" 44 | 45 | #define ASI_MAJOR 61 /* Set to 0 for dynamic allocation. 46 | * Otherwise, 61 is available. 47 | * See /usr/src/linux/Documentation/devices.txt */ 48 | 49 | #define ASI_TX_BUFFERS_MIN 2 /* This must be at least 2 */ 50 | /* The minimum transmit buffer size must be positive, divisible by 8, 51 | * and large enough that the buffers aren't transferred to the onboard FIFOs 52 | * too quickly for the machine to handle the interrupts. 53 | * This is especially a problem at startup, when the FIFOs are empty. 54 | * Relevant factors include onboard FIFO size, PCI bus throughput, 55 | * processor speed, and interrupt latency. */ 56 | #define ASI_TX_BUFSIZE_MIN 1024 57 | #define ASI_RX_BUFFERS_MIN 2 /* This must be at least 2 */ 58 | #define ASI_RX_BUFSIZE_MIN 8 /* This must be positive and divisible by 8 */ 59 | 60 | #define ASI_TX_BUFFERS 54 /* This must be at least 2 */ 61 | #define ASI_TX_BUFSIZE 38352 /* This must be positive and divisible by 8 */ 62 | #define ASI_RX_BUFFERS 54 /* This must be at least 2 */ 63 | #define ASI_RX_BUFSIZE 38352 /* This must be positive and divisible by 8 */ 64 | 65 | /* Ioctl () definitions */ 66 | #define ASI_IOC_MAGIC '?' /* This ioctl magic number is currently free. See 67 | * /usr/src/linux/Documentation/ioctl-number.txt */ 68 | 69 | #define ASI_IOC_TXGETCAP _IOR(ASI_IOC_MAGIC, 1, unsigned int) 70 | #define ASI_IOC_TXGETEVENTS _IOR(ASI_IOC_MAGIC, 2, unsigned int) 71 | #define ASI_IOC_TXGETBUFLEVEL _IOR(ASI_IOC_MAGIC, 3, unsigned int) 72 | #define ASI_IOC_TXSETSTUFFING _IOW(ASI_IOC_MAGIC, 4, struct asi_txstuffing) 73 | #define ASI_IOC_TXGETBYTECOUNT _IOR(ASI_IOC_MAGIC, 5, unsigned int) 74 | /* #define ASI_IOC_TXGETFIFO _IOR(ASI_IOC_MAGIC, 6, int) */ 75 | #define ASI_IOC_TXGETTXD _IOR(ASI_IOC_MAGIC, 7, int) 76 | #define ASI_IOC_TXGET27COUNT _IOR(ASI_IOC_MAGIC, 8, unsigned int) 77 | /* Provide compatibility with applications compiled for older API */ 78 | #define ASI_IOC_TXSETPID_DEPRECATED _IOR(ASI_IOC_MAGIC, 9, unsigned int) 79 | #define ASI_IOC_TXSETPID _IOW(ASI_IOC_MAGIC, 9, unsigned int) 80 | #define ASI_IOC_TXGETPCRSTAMP _IOR(ASI_IOC_MAGIC, 10, struct asi_pcrstamp) 81 | /* Provide compatibility with applications compiled for older API */ 82 | #define ASI_IOC_TXCHANGENEXTIP_DEPRECATED _IOR(ASI_IOC_MAGIC, 11, int) 83 | #define ASI_IOC_TXCHANGENEXTIP _IOW(ASI_IOC_MAGIC, 11, int) 84 | 85 | #define ASI_IOC_RXGETCAP _IOR(ASI_IOC_MAGIC, 65, unsigned int) 86 | #define ASI_IOC_RXGETEVENTS _IOR(ASI_IOC_MAGIC, 66, unsigned int) 87 | #define ASI_IOC_RXGETBUFLEVEL _IOR(ASI_IOC_MAGIC, 67, unsigned int) 88 | /* #define ASI_IOC_RXSETREFRAME _IOW(ASI_IOC_MAGIC, 68, int) */ 89 | #define ASI_IOC_RXGETSTATUS _IOR(ASI_IOC_MAGIC, 69, int) 90 | #define ASI_IOC_RXGETBYTECOUNT _IOR(ASI_IOC_MAGIC, 70, unsigned int) 91 | /* #define ASI_IOC_RXGETFIFO _IOR(ASI_IOC_MAGIC, 71, int) */ 92 | #define ASI_IOC_RXSETINVSYNC _IOW(ASI_IOC_MAGIC, 72, int) 93 | #define ASI_IOC_RXGETCARRIER _IOR(ASI_IOC_MAGIC, 73, int) 94 | #define ASI_IOC_RXSETDSYNC _IOW(ASI_IOC_MAGIC, 74, int) 95 | #define ASI_IOC_RXGETRXD _IOR(ASI_IOC_MAGIC, 75, int) 96 | #define ASI_IOC_RXSETPF _IOW(ASI_IOC_MAGIC, 76, unsigned int [256]) 97 | /* #define ASI_IOC_RXSETPFE _IOW(ASI_IOC_MAGIC, 77, int) */ 98 | #define ASI_IOC_RXSETPID0 _IOW(ASI_IOC_MAGIC, 78, int) 99 | #define ASI_IOC_RXGETPID0COUNT _IOR(ASI_IOC_MAGIC, 79, unsigned int) 100 | #define ASI_IOC_RXSETPID1 _IOW(ASI_IOC_MAGIC, 80, int) 101 | #define ASI_IOC_RXGETPID1COUNT _IOR(ASI_IOC_MAGIC, 81, unsigned int) 102 | #define ASI_IOC_RXSETPID2 _IOW(ASI_IOC_MAGIC, 82, int) 103 | #define ASI_IOC_RXGETPID2COUNT _IOR(ASI_IOC_MAGIC, 83, unsigned int) 104 | #define ASI_IOC_RXSETPID3 _IOW(ASI_IOC_MAGIC, 84, int) 105 | #define ASI_IOC_RXGETPID3COUNT _IOR(ASI_IOC_MAGIC, 85, unsigned int) 106 | /* #define ASI_IOC_RXGETSTAMP _IOR(ASI_IOC_MAGIC, 86, unsigned int) */ 107 | #define ASI_IOC_RXGET27COUNT _IOR(ASI_IOC_MAGIC, 87, unsigned int) 108 | #define ASI_IOC_RXGETSTATUS2 _IOR(ASI_IOC_MAGIC, 88, int) 109 | /* Provide compatibility with applications compiled for older API */ 110 | #define ASI_IOC_RXSETINPUT_DEPRECATED _IOR(ASI_IOC_MAGIC, 89, int) 111 | #define ASI_IOC_RXSETINPUT _IOW(ASI_IOC_MAGIC, 89, int) 112 | #define ASI_IOC_RXGETRXD2 _IOR(ASI_IOC_MAGIC, 90, int) 113 | 114 | #define ASI_IOC_GETID _IOR(ASI_IOC_MAGIC, 129, unsigned int) 115 | #define ASI_IOC_GETVERSION _IOR(ASI_IOC_MAGIC, 130, unsigned int) 116 | 117 | /* Transmitter event flag bit locations */ 118 | #define ASI_EVENT_TX_BUFFER_ORDER 0 119 | #define ASI_EVENT_TX_BUFFER (1 << ASI_EVENT_TX_BUFFER_ORDER) 120 | #define ASI_EVENT_TX_FIFO_ORDER 1 121 | #define ASI_EVENT_TX_FIFO (1 << ASI_EVENT_TX_FIFO_ORDER) 122 | #define ASI_EVENT_TX_DATA_ORDER 2 123 | #define ASI_EVENT_TX_DATA (1 << ASI_EVENT_TX_DATA_ORDER) 124 | 125 | /* Receiver event flag bit locations */ 126 | #define ASI_EVENT_RX_BUFFER_ORDER 0 127 | #define ASI_EVENT_RX_BUFFER (1 << ASI_EVENT_RX_BUFFER_ORDER) 128 | #define ASI_EVENT_RX_FIFO_ORDER 1 129 | #define ASI_EVENT_RX_FIFO (1 << ASI_EVENT_RX_FIFO_ORDER) 130 | #define ASI_EVENT_RX_CARRIER_ORDER 2 131 | #define ASI_EVENT_RX_CARRIER (1 << ASI_EVENT_RX_CARRIER_ORDER) 132 | #define ASI_EVENT_RX_AOS_ORDER 3 133 | #define ASI_EVENT_RX_AOS (1 << ASI_EVENT_RX_AOS_ORDER) 134 | #define ASI_EVENT_RX_LOS_ORDER 4 135 | #define ASI_EVENT_RX_LOS (1 << ASI_EVENT_RX_LOS_ORDER) 136 | #define ASI_EVENT_RX_DATA_ORDER 5 137 | #define ASI_EVENT_RX_DATA (1 << ASI_EVENT_RX_DATA_ORDER) 138 | 139 | /** 140 | * asi_txstuffing - Transmitter stuffing parameters 141 | * @ib: interbyte stuffing 142 | * @ip: interpacket stuffing 143 | * @normal_ip: FT0 144 | * @big_ip: FT1 145 | * @il_normal: IL0 146 | * @il_big: IL1 147 | **/ 148 | struct asi_txstuffing { 149 | /* Number of K28.5 characters to insert between packet bytes */ 150 | unsigned int ib; 151 | 152 | /* Base number of K28.5 characters to insert between packets, 153 | * not including the two required by ASI */ 154 | unsigned int ip; 155 | 156 | /* Number of packets with (ip) bytes of interpacket stuffing 157 | * per finetuning cycle */ 158 | unsigned int normal_ip; 159 | 160 | /* Number of packets with (ip + 1) bytes of interpacket stuffing 161 | * per finetuning cycle */ 162 | unsigned int big_ip; 163 | 164 | /* Number of packets with (ip) bytes of interpacket stuffing 165 | * per interleaved finetuning cycle */ 166 | unsigned int il_normal; 167 | 168 | /* Number of packets with (ip + 1) bytes of interpacket stuffing 169 | * per interleaved finetuning cycle */ 170 | unsigned int il_big; 171 | }; 172 | 173 | /** 174 | * asi_pcrstamp - PCR - departure time pair 175 | * @adaptation_field_length: adaptation field length 176 | * @adaptation_field_flags: adaptation field flags 177 | * @PCR: a program clock reference 178 | * @count: departure time of this PCR, in 1 / 27 MHz 179 | **/ 180 | struct asi_pcrstamp { 181 | unsigned char adaptation_field_length; 182 | unsigned char adaptation_field_flags; 183 | unsigned char PCR[6]; 184 | long long int count; 185 | }; 186 | 187 | /* Interface capabilities */ 188 | #define ASI_CAP_TX_MAKE204 0x00000004 189 | #define ASI_CAP_TX_FINETUNING 0x00000008 190 | #define ASI_CAP_TX_BYTECOUNTER 0x00000010 191 | #define ASI_CAP_TX_SETCLKSRC 0x00000020 192 | #define ASI_CAP_TX_FIFOUNDERRUN 0x00000040 193 | #define ASI_CAP_TX_LARGEIB 0x00000080 194 | #define ASI_CAP_TX_INTERLEAVING 0x00000100 195 | #define ASI_CAP_TX_DATA 0x00000200 196 | #define ASI_CAP_TX_RXCLKSRC 0x00000400 197 | /* #define ASI_CAP_TX_COMPOSITEREF 0x00000800 */ 198 | #define ASI_CAP_TX_PCRSTAMP 0x00001000 199 | #define ASI_CAP_TX_CHANGENEXTIP 0x00002000 200 | #define ASI_CAP_TX_27COUNTER 0x00004000 201 | #define ASI_CAP_TX_BYTESOR27 0x00008000 202 | #define ASI_CAP_TX_TIMESTAMPS 0x00010000 203 | #define ASI_CAP_TX_PTIMESTAMPS 0x00020000 204 | #define ASI_CAP_TX_NULLPACKETS 0x00040000 205 | #define ASI_CAP_TX_EXTCLKSRC2 0x00080000 206 | 207 | #define ASI_CAP_RX_SYNC 0x00000004 208 | #define ASI_CAP_RX_MAKE188 0x00000008 209 | #define ASI_CAP_RX_BYTECOUNTER 0x00000010 210 | /* #define ASI_CAP_RX_FIFOSTATUS 0x00000020 */ 211 | #define ASI_CAP_RX_INVSYNC 0x00000040 212 | #define ASI_CAP_RX_CD 0x00000080 213 | #define ASI_CAP_RX_DSYNC 0x00000100 214 | #define ASI_CAP_RX_DATA 0x00000200 215 | #define ASI_CAP_RX_PIDFILTER 0x00000400 216 | #define ASI_CAP_RX_PIDCOUNTER 0x00000800 217 | #define ASI_CAP_RX_4PIDCOUNTER 0x00001000 218 | #define ASI_CAP_RX_FORCEDMA 0x00002000 219 | #define ASI_CAP_RX_27COUNTER 0x00004000 220 | #define ASI_CAP_RX_BYTESOR27 0x00008000 221 | #define ASI_CAP_RX_TIMESTAMPS 0x00010000 222 | #define ASI_CAP_RX_PTIMESTAMPS 0x00020000 223 | #define ASI_CAP_RX_NULLPACKETS 0x00040000 224 | #define ASI_CAP_RX_REDUNDANT 0x00080000 225 | #define ASI_CAP_RX_DATA2 0x00100000 226 | 227 | /* Transmitter clock source settings */ 228 | #define ASI_CTL_TX_CLKSRC_ONBOARD 0 229 | #define ASI_CTL_TX_CLKSRC_EXT 1 230 | #define ASI_CTL_TX_CLKSRC_RX 2 231 | #define ASI_CTL_TX_CLKSRC_EXT2 3 232 | 233 | /* Transmitter mode settings */ 234 | #define ASI_CTL_TX_MODE_188 0 235 | #define ASI_CTL_TX_MODE_204 1 236 | #define ASI_CTL_TX_MODE_MAKE204 2 237 | 238 | /* Receiver mode settings */ 239 | #define ASI_CTL_RX_MODE_RAW 0 240 | #define ASI_CTL_RX_MODE_188 1 241 | #define ASI_CTL_RX_MODE_204 2 242 | #define ASI_CTL_RX_MODE_AUTO 3 243 | #define ASI_CTL_RX_MODE_AUTOMAKE188 4 244 | #define ASI_CTL_RX_MODE_204MAKE188 5 245 | 246 | /* Timestamping settings */ 247 | #define ASI_CTL_TSTAMP_NONE 0 248 | #define ASI_CTL_TSTAMP_APPEND 1 249 | #define ASI_CTL_TSTAMP_PREPEND 2 250 | 251 | /* Transport settings */ 252 | #define ASI_CTL_TRANSPORT_DVB_ASI 0 253 | #define ASI_CTL_TRANSPORT_SMPTE_310M 1 254 | 255 | #endif 256 | 257 | -------------------------------------------------------------------------------- /input/sdi/sdi.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * sdi.c: SDI functions 3 | ***************************************************************************** 4 | * Copyright (C) 2010 Open Broadcast Systems Ltd. 5 | * 6 | * Authors: Kieran Kunhya 7 | * Some code originates from the FFmpeg project 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 22 | * 23 | *****************************************************************************/ 24 | 25 | #include "sdi.h" 26 | #include 27 | 28 | #define READ_PIXELS(a, b, c) \ 29 | do { \ 30 | val = av_le2ne32( *src++ ); \ 31 | *a++ = val & 0x3ff; \ 32 | *b++ = (val >> 10) & 0x3ff; \ 33 | *c++ = (val >> 20) & 0x3ff; \ 34 | } while (0) 35 | 36 | void obe_v210_planar_unpack_c( const uint32_t *src, uint16_t *y, uint16_t *u, uint16_t *v, int width ) 37 | { 38 | uint32_t val; 39 | 40 | for( int i = 0; i < width - 5; i += 6 ) 41 | { 42 | READ_PIXELS( u, y, v ); 43 | READ_PIXELS( y, u, y ); 44 | READ_PIXELS( v, y, u ); 45 | READ_PIXELS( y, v, y ); 46 | } 47 | } 48 | 49 | /* Convert v210 to the native HD-SDI pixel format. */ 50 | void obe_v210_line_to_nv20_c( uint32_t *src, uint16_t *dst, int width ) 51 | { 52 | int w; 53 | uint32_t val = 0; 54 | uint16_t *uv = dst + width; 55 | for( w = 0; w < width - 5; w += 6 ) 56 | { 57 | READ_PIXELS( uv, dst, uv ); 58 | READ_PIXELS( dst, uv, dst ); 59 | READ_PIXELS( uv, dst, uv ); 60 | READ_PIXELS( dst, uv, dst ); 61 | } 62 | 63 | if( w < width - 1 ) 64 | { 65 | READ_PIXELS(uv, dst, uv); 66 | 67 | val = av_le2ne32( *src++ ); 68 | *dst++ = val & 0x3ff; 69 | } 70 | 71 | if( w < width - 3 ) 72 | { 73 | *uv++ = (val >> 10) & 0x3ff; 74 | *dst++ = (val >> 20) & 0x3ff; 75 | 76 | val = av_le2ne32( *src++ ); 77 | *uv++ = val & 0x3ff; 78 | *dst++ = (val >> 10) & 0x3ff; 79 | } 80 | } 81 | 82 | /* Convert v210 to the native SD-SDI pixel format. 83 | * Width is always 720 samples */ 84 | void obe_v210_line_to_uyvy_c( uint32_t *src, uint16_t *dst, int width ) 85 | { 86 | uint32_t val; 87 | for( int i = 0; i < width; i += 6 ) 88 | { 89 | READ_PIXELS( dst, dst, dst ); 90 | READ_PIXELS( dst, dst, dst ); 91 | READ_PIXELS( dst, dst, dst ); 92 | READ_PIXELS( dst, dst, dst ); 93 | } 94 | } 95 | 96 | /* Convert YUV422P10 to the native HD-SDI pixel format. */ 97 | void obe_yuv422p10_line_to_nv20_c( uint16_t *y, uint16_t *u, uint16_t *v, uint16_t *dst, int width ) 98 | { 99 | uint16_t *uv = dst + width; 100 | for( int i = 0; i < width; i += 2 ) 101 | { 102 | *dst++ = *y++; 103 | *dst++ = *y++; 104 | *uv++ = *u++; 105 | *uv++ = *v++; 106 | } 107 | } 108 | 109 | /* Convert YUV422P10 to the native SD-SDI pixel format. 110 | * Width is always 720 samples */ 111 | void obe_yuv422p10_line_to_uyvy_c( uint16_t *y, uint16_t *u, uint16_t *v, uint16_t *dst, int width ) 112 | { 113 | for( int i = 0; i < width; i += 2 ) 114 | { 115 | *dst++ = *u++; 116 | *dst++ = *y++; 117 | *dst++ = *v++; 118 | *dst++ = *y++; 119 | } 120 | } 121 | 122 | /* Downscale 10-bit lines to 8-bit lines for processing by libzvbi. 123 | * Width is always 720*2 samples */ 124 | void obe_downscale_line_c( uint16_t *src, uint8_t *dst, int lines ) 125 | { 126 | for( int i = 0; i < 720*2*lines; i++ ) 127 | dst[i] = src[i] >> 2; 128 | } 129 | 130 | void obe_blank_line_nv20_c( uint16_t *dst, int width ) 131 | { 132 | uint16_t *uv = dst + width; 133 | for( int i = 0; i < width; i++ ) 134 | { 135 | *dst++ = 0x40; 136 | *uv++ = 0x200; 137 | } 138 | } 139 | 140 | void obe_blank_line_uyvy_c( uint16_t *dst, int width ) 141 | { 142 | for( int i = 0; i < width; i++ ) 143 | { 144 | *dst++ = 0x200; 145 | *dst++ = 0x40; 146 | } 147 | } 148 | 149 | int add_non_display_services( obe_sdi_non_display_data_t *non_display_data, obe_int_input_stream_t *stream, int location ) 150 | { 151 | int idx = 0, count = 0; 152 | 153 | for( int i = 0; i < non_display_data->num_frame_data; i++ ) 154 | { 155 | if( non_display_data->frame_data[i].type == MISC_TELETEXT ) 156 | continue; 157 | else if( non_display_data->frame_data[i].location == location ) 158 | count++; 159 | } 160 | 161 | stream->num_frame_data = count; 162 | 163 | if( !stream->num_frame_data ) 164 | { 165 | stream->frame_data = NULL; 166 | return 0; 167 | } 168 | 169 | stream->frame_data = calloc( stream->num_frame_data, sizeof(*stream->frame_data) ); 170 | if( !stream->frame_data && stream->num_frame_data ) 171 | return -1; 172 | 173 | for( int i = 0; i < non_display_data->num_frame_data; i++ ) 174 | { 175 | if( non_display_data->frame_data[i].type == MISC_TELETEXT ) 176 | continue; 177 | else if( non_display_data->frame_data[i].location == location ) 178 | { 179 | stream->frame_data[idx].type = non_display_data->frame_data[i].type; 180 | stream->frame_data[idx].source = non_display_data->frame_data[i].source; 181 | stream->frame_data[idx].num_lines = non_display_data->frame_data[i].num_lines; 182 | memcpy( stream->frame_data[idx].lines, non_display_data->frame_data[i].lines, non_display_data->frame_data[i].num_lines * sizeof(int) ); 183 | idx++; 184 | } 185 | } 186 | 187 | return 0; 188 | } 189 | 190 | int check_probed_non_display_data( obe_sdi_non_display_data_t *non_display_data, int type ) 191 | { 192 | for( int i = 0; i < non_display_data->num_frame_data; i++ ) 193 | { 194 | if( non_display_data->frame_data[i].type == type ) 195 | return 1; 196 | } 197 | 198 | return 0; 199 | } 200 | 201 | int check_active_non_display_data( obe_raw_frame_t *raw_frame, int type ) 202 | { 203 | for( int i = 0; i < raw_frame->num_user_data; i++ ) 204 | { 205 | if( raw_frame->user_data[i].type == type ) 206 | return 1; 207 | } 208 | 209 | return 0; 210 | } 211 | 212 | int check_user_selected_non_display_data( obe_t *h, int type, int location ) 213 | { 214 | obe_output_stream_t *output_stream; 215 | 216 | if( location == USER_DATA_LOCATION_DVB_STREAM ) 217 | { 218 | output_stream = get_output_stream( h, VBI_RAW ); 219 | if( !output_stream ) 220 | return 0; 221 | 222 | switch( type ) 223 | { 224 | case MISC_TELETEXT: 225 | return output_stream->dvb_vbi_opts.ttx; 226 | case MISC_TELETEXT_INVERTED: 227 | return output_stream->dvb_vbi_opts.inverted_ttx; 228 | case MISC_VPS: 229 | return output_stream->dvb_vbi_opts.vps; 230 | case MISC_WSS: 231 | return output_stream->dvb_vbi_opts.wss; 232 | } 233 | } 234 | else if( location == USER_DATA_LOCATION_FRAME ) 235 | { 236 | /* Assumes video frame has stream_id=0 */ 237 | output_stream = get_output_stream( h, 0 ); 238 | /* Should never happen */ 239 | if( !output_stream ) 240 | return 0; 241 | 242 | switch( type ) 243 | { 244 | case CAPTIONS_CEA_608: 245 | return output_stream->video_anc.cea_608; 246 | case CAPTIONS_CEA_708: 247 | return output_stream->video_anc.cea_708; 248 | case MISC_AFD: 249 | return output_stream->video_anc.afd; 250 | /* Actually WSS to AFD conversion */ 251 | case MISC_WSS: 252 | return output_stream->video_anc.wss_to_afd; 253 | } 254 | } 255 | 256 | return 0; 257 | } 258 | 259 | int add_teletext_service( obe_sdi_non_display_data_t *non_display_data, obe_int_input_stream_t *stream ) 260 | { 261 | stream->frame_data = calloc( 1, sizeof(*stream->frame_data) ); 262 | if( !stream->frame_data ) 263 | return -1; 264 | 265 | for( int i = 0; i < non_display_data->num_frame_data; i++ ) 266 | { 267 | if( non_display_data->frame_data[i].type == MISC_TELETEXT ) 268 | { 269 | stream->frame_data[0].type = non_display_data->frame_data[i].type; 270 | stream->frame_data[0].source = non_display_data->frame_data[i].source; 271 | stream->frame_data[0].num_lines = non_display_data->frame_data[i].num_lines; 272 | memcpy( stream->frame_data[0].lines, non_display_data->frame_data[0].lines, non_display_data->frame_data[0].num_lines * sizeof(int) ); 273 | } 274 | } 275 | 276 | return 0; 277 | } 278 | 279 | /* FIXME: these functions don't include the centre line */ 280 | int sdi_next_line( int format, int line_smpte ) 281 | { 282 | int i; 283 | 284 | if( !IS_INTERLACED( format ) ) 285 | return line_smpte+1; 286 | 287 | for( i = 0; field_start_lines[i].format != -1; i++ ) 288 | { 289 | if( format == field_start_lines[i].format ) 290 | break; 291 | } 292 | 293 | if( line_smpte >= field_start_lines[i].line && line_smpte < field_start_lines[i].field_two ) 294 | return field_start_lines[i].field_two - field_start_lines[i].line + line_smpte; 295 | else 296 | return line_smpte - field_start_lines[i].field_two + field_start_lines[i].line + 1; 297 | } 298 | 299 | int obe_convert_smpte_to_analogue( int format, int line_smpte, int *line_analogue, int *field ) 300 | { 301 | int i; 302 | 303 | if( !IS_INTERLACED( format ) ) 304 | return -1; 305 | 306 | for( i = 0; field_start_lines[i].format != -1; i++ ) 307 | { 308 | if( format == field_start_lines[i].format ) 309 | break; 310 | } 311 | 312 | if( line_smpte >= field_start_lines[i].line && line_smpte < field_start_lines[i].field_two ) 313 | { 314 | *line_analogue = line_smpte; 315 | *field = 1; 316 | } 317 | else 318 | { 319 | *line_analogue = line_smpte - field_start_lines[i].field_two + field_start_lines[i].line; 320 | *field = 2; 321 | } 322 | 323 | return 0; 324 | } 325 | 326 | int obe_convert_analogue_to_smpte( int format, int line_analogue, int field, int *line_smpte ) 327 | { 328 | int i; 329 | 330 | if( !IS_INTERLACED( format ) ) 331 | return -1; 332 | 333 | if( field == 1 ) 334 | *line_smpte = line_analogue; 335 | else 336 | { 337 | for( i = 0; field_start_lines[i].format != -1; i++ ) 338 | { 339 | if( format == field_start_lines[i].format ) 340 | break; 341 | } 342 | 343 | *line_smpte = field_start_lines[i].field_two - field_start_lines[i].line + line_analogue; 344 | } 345 | 346 | return 0; 347 | } 348 | --------------------------------------------------------------------------------