gst-plugins-good  1.20.3
About: GStreamer (Good Plugins) is a library for constructing of graphs of media-handling components. A set of good-quality plug-ins (under LGPL license).
  Fossies Dox: gst-plugins-good-1.20.3.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

RaspiStill.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <unistd.h>
#include <errno.h>
#include <sysexits.h>
#include "bcm_host.h"
#include "interface/vcos/vcos.h"
#include "interface/mmal/mmal.h"
#include "interface/mmal/mmal_logging.h"
#include "interface/mmal/mmal_buffer.h"
#include "interface/mmal/util/mmal_util.h"
#include "interface/mmal/util/mmal_util_params.h"
#include "interface/mmal/util/mmal_default_components.h"
#include "interface/mmal/util/mmal_connection.h"
#include "RaspiCamControl.h"
#include "RaspiPreview.h"
#include "RaspiCLI.h"
#include <semaphore.h>
Include dependency graph for RaspiStill.c:

Go to the source code of this file.

Data Structures

struct  RASPISTILL_STATE
 
struct  PORT_USERDATA
 

Macros

#define _GNU_SOURCE
 
#define VERSION_STRING   "v1.3.2"
 
#define CAMERA_NUMBER   0
 Camera number to use - we only have one camera, indexed from 0. More...
 
#define MMAL_CAMERA_PREVIEW_PORT   0
 
#define MMAL_CAMERA_VIDEO_PORT   1
 
#define MMAL_CAMERA_CAPTURE_PORT   2
 
#define STILLS_FRAME_RATE_NUM   15
 
#define STILLS_FRAME_RATE_DEN   1
 
#define VIDEO_OUTPUT_BUFFERS_NUM   3
 Video render needs at least 2 buffers. More...
 
#define MAX_USER_EXIF_TAGS   32
 
#define MAX_EXIF_PAYLOAD_LENGTH   128
 
#define CommandHelp   0
 Comamnd ID's and Structure defining our command line options. More...
 
#define CommandWidth   1
 
#define CommandHeight   2
 
#define CommandQuality   3
 
#define CommandRaw   4
 
#define CommandOutput   5
 
#define CommandVerbose   6
 
#define CommandTimeout   7
 
#define CommandThumbnail   8
 
#define CommandDemoMode   9
 
#define CommandEncoding   10
 
#define CommandExifTag   11
 
#define CommandTimelapse   12
 
#define CommandFullResPreview   13
 
#define CommandLink   14
 

Functions

int mmal_status_to_int (MMAL_STATUS_T status)
 
static void display_valid_parameters (char *app_name)
 
static void store_exif_tag (RASPISTILL_STATE *state, const char *exif_tag)
 
static void default_status (RASPISTILL_STATE *state)
 
static void dump_status (RASPISTILL_STATE *state)
 
static int parse_cmdline (int argc, const char **argv, RASPISTILL_STATE *state)
 
static void camera_control_callback (MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
 
static void encoder_buffer_callback (MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
 
static MMAL_STATUS_T create_camera_component (RASPISTILL_STATE *state)
 
static void destroy_camera_component (RASPISTILL_STATE *state)
 
static MMAL_STATUS_T create_encoder_component (RASPISTILL_STATE *state)
 
static void destroy_encoder_component (RASPISTILL_STATE *state)
 
static MMAL_STATUS_T add_exif_tag (RASPISTILL_STATE *state, const char *exif_tag)
 
static void add_exif_tags (RASPISTILL_STATE *state)
 
static MMAL_STATUS_T connect_ports (MMAL_PORT_T *output_port, MMAL_PORT_T *input_port, MMAL_CONNECTION_T **connection)
 
MMAL_STATUS_T create_filenames (char **finalName, char **tempName, char *pattern, int frame)
 
static void check_disable_port (MMAL_PORT_T *port)
 
static void signal_handler (int signal_number)
 
int main (int argc, const char **argv)
 

Variables

static COMMAND_LIST cmdline_commands []
 
static int cmdline_commands_size = sizeof(cmdline_commands) / sizeof(cmdline_commands[0])
 
struct {
   char *   format
 
   MMAL_FOURCC_T   encoding
 
encoding_xref []
 
static int encoding_xref_size = sizeof(encoding_xref) / sizeof(encoding_xref[0])
 

Detailed Description

Command line program to capture a still frame and encode it to file. Also optionally display a preview/viewfinder of current camera input.

Date
31 Jan 2013 \Author: James Hughes

Description

3 components are created; camera, preview and JPG encoder. Camera component has three ports, preview, video and stills. This program connects preview and stills to the preview and jpg encoder. Using mmal we don't need to worry about buffers between these components, but we do need to handle buffers from the encoder, which are simply written straight to the file in the requisite buffer callback.

We use the RaspiCamControl code to handle the specific camera settings.

Definition in file RaspiStill.c.

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE

Definition at line 53 of file RaspiStill.c.

◆ CAMERA_NUMBER

#define CAMERA_NUMBER   0

Camera number to use - we only have one camera, indexed from 0.

Definition at line 84 of file RaspiStill.c.

◆ CommandDemoMode

#define CommandDemoMode   9

Definition at line 160 of file RaspiStill.c.

◆ CommandEncoding

#define CommandEncoding   10

Definition at line 161 of file RaspiStill.c.

◆ CommandExifTag

#define CommandExifTag   11

Definition at line 162 of file RaspiStill.c.

◆ CommandFullResPreview

#define CommandFullResPreview   13

Definition at line 164 of file RaspiStill.c.

◆ CommandHeight

#define CommandHeight   2

Definition at line 153 of file RaspiStill.c.

◆ CommandHelp

#define CommandHelp   0

Comamnd ID's and Structure defining our command line options.

Definition at line 151 of file RaspiStill.c.

◆ CommandLink

#define CommandLink   14

Definition at line 165 of file RaspiStill.c.

◆ CommandOutput

#define CommandOutput   5

Definition at line 156 of file RaspiStill.c.

◆ CommandQuality

#define CommandQuality   3

Definition at line 154 of file RaspiStill.c.

◆ CommandRaw

#define CommandRaw   4

Definition at line 155 of file RaspiStill.c.

◆ CommandThumbnail

#define CommandThumbnail   8

Definition at line 159 of file RaspiStill.c.

◆ CommandTimelapse

#define CommandTimelapse   12

Definition at line 163 of file RaspiStill.c.

◆ CommandTimeout

#define CommandTimeout   7

Definition at line 158 of file RaspiStill.c.

◆ CommandVerbose

#define CommandVerbose   6

Definition at line 157 of file RaspiStill.c.

◆ CommandWidth

#define CommandWidth   1

Definition at line 152 of file RaspiStill.c.

◆ MAX_EXIF_PAYLOAD_LENGTH

#define MAX_EXIF_PAYLOAD_LENGTH   128

Definition at line 100 of file RaspiStill.c.

◆ MAX_USER_EXIF_TAGS

#define MAX_USER_EXIF_TAGS   32

Definition at line 99 of file RaspiStill.c.

◆ MMAL_CAMERA_CAPTURE_PORT

#define MMAL_CAMERA_CAPTURE_PORT   2

Definition at line 89 of file RaspiStill.c.

◆ MMAL_CAMERA_PREVIEW_PORT

#define MMAL_CAMERA_PREVIEW_PORT   0

Definition at line 87 of file RaspiStill.c.

◆ MMAL_CAMERA_VIDEO_PORT

#define MMAL_CAMERA_VIDEO_PORT   1

Definition at line 88 of file RaspiStill.c.

◆ STILLS_FRAME_RATE_DEN

#define STILLS_FRAME_RATE_DEN   1

Definition at line 94 of file RaspiStill.c.

◆ STILLS_FRAME_RATE_NUM

#define STILLS_FRAME_RATE_NUM   15

Definition at line 93 of file RaspiStill.c.

◆ VERSION_STRING

#define VERSION_STRING   "v1.3.2"

Definition at line 63 of file RaspiStill.c.

◆ VIDEO_OUTPUT_BUFFERS_NUM

#define VIDEO_OUTPUT_BUFFERS_NUM   3

Video render needs at least 2 buffers.

Definition at line 97 of file RaspiStill.c.

Function Documentation

◆ add_exif_tag()

static MMAL_STATUS_T add_exif_tag ( RASPISTILL_STATE state,
const char *  exif_tag 
)
static

Add an exif tag to the capture

Parameters
statePointer to state control struct
exif_tagString containing a "key=value" pair.
Returns
Returns a MMAL_STATUS_T giving result of operation

Definition at line 975 of file RaspiStill.c.

References RASPISTILL_STATE::encoder_component, and MAX_EXIF_PAYLOAD_LENGTH.

Referenced by add_exif_tags().

◆ add_exif_tags()

static void add_exif_tags ( RASPISTILL_STATE state)
static

Add a basic set of EXIF tags to the capture Make, Time etc

Parameters
statePointer to state control struct

Definition at line 1007 of file RaspiStill.c.

References add_exif_tag(), RASPISTILL_STATE::exifTags, MAX_USER_EXIF_TAGS, and RASPISTILL_STATE::numExifTags.

Referenced by main().

◆ camera_control_callback()

static void camera_control_callback ( MMAL_PORT_T *  port,
MMAL_BUFFER_HEADER_T *  buffer 
)
static

buffer header callback function for camera control

No actions taken in current version

Parameters
portPointer to port from which callback originated
buffermmal buffer header pointer

Definition at line 555 of file RaspiStill.c.

References vcos_log_error.

Referenced by create_camera_component().

◆ check_disable_port()

static void check_disable_port ( MMAL_PORT_T *  port)
static

Checks if specified port is valid and enabled, then disables it

Parameters
portPointer the port

Definition at line 1131 of file RaspiStill.c.

Referenced by main().

◆ connect_ports()

static MMAL_STATUS_T connect_ports ( MMAL_PORT_T *  output_port,
MMAL_PORT_T *  input_port,
MMAL_CONNECTION_T **  connection 
)
static

Connect two specific ports together

Parameters
output_portPointer the output port
input_portPointer the input port
Pointerto a mmal connection pointer, reassigned if function successful
Returns
Returns a MMAL_STATUS_T giving result of operation

Definition at line 1079 of file RaspiStill.c.

Referenced by main().

◆ create_camera_component()

◆ create_encoder_component()

static MMAL_STATUS_T create_encoder_component ( RASPISTILL_STATE state)
static

Create the encoder component, set up its ports

Parameters
statePointer to state control struct. encoder_component member set to the created camera_component if successfull.
Returns
a MMAL_STATUS, MMAL_SUCCESS if all OK, something else otherwise

Definition at line 839 of file RaspiStill.c.

References RASPISTILL_STATE::encoder_component, RASPISTILL_STATE::encoder_pool, RASPISTILL_STATE::encoding, fprintf, MMAL_PARAM_THUMBNAIL_CONFIG_T::height, MMAL_PARAM_THUMBNAIL_CONFIG_T::quality, RASPISTILL_STATE::quality, RASPISTILL_STATE::thumbnailConfig, vcos_log_error, RASPISTILL_STATE::verbose, and MMAL_PARAM_THUMBNAIL_CONFIG_T::width.

Referenced by main().

◆ create_filenames()

MMAL_STATUS_T create_filenames ( char **  finalName,
char **  tempName,
char *  pattern,
int  frame 
)

Allocates and generates a filename based on the user-supplied pattern and the frame number. On successful return, finalName and tempName point to malloc()ed strings which must be freed externally. (On failure, returns nulls that don't need free()ing.)

Parameters
finalNamepointer receives an
patternsprintf pattern with d to be replaced by frame
framefor timelapse, the frame number
Returns
Returns a MMAL_STATUS_T giving result of operation

Definition at line 1109 of file RaspiStill.c.

Referenced by main().

◆ default_status()

◆ destroy_camera_component()

static void destroy_camera_component ( RASPISTILL_STATE state)
static

Destroy the camera component

Parameters
statePointer to state control struct

Definition at line 821 of file RaspiStill.c.

References RASPISTILL_STATE::camera_component.

Referenced by main().

◆ destroy_encoder_component()

static void destroy_encoder_component ( RASPISTILL_STATE state)
static

Destroy the encoder component

Parameters
statePointer to state control struct

Definition at line 952 of file RaspiStill.c.

References RASPISTILL_STATE::encoder_component, and RASPISTILL_STATE::encoder_pool.

Referenced by main().

◆ display_valid_parameters()

static void display_valid_parameters ( char *  app_name)
static

Display usage information for the application to stdout

Parameters
app_nameString to display as the application name

Definition at line 527 of file RaspiStill.c.

References cmdline_commands, cmdline_commands_size, fprintf, raspicamcontrol_display_help(), raspicli_display_help(), and raspipreview_display_help().

Referenced by main(), and parse_cmdline().

◆ dump_status()

◆ encoder_buffer_callback()

static void encoder_buffer_callback ( MMAL_PORT_T *  port,
MMAL_BUFFER_HEADER_T *  buffer 
)
static

buffer header callback function for encoder

Callback will dump buffer data to the specific file

Parameters
portPointer to port from which callback originated
buffermmal buffer header pointer

Definition at line 576 of file RaspiStill.c.

References PORT_USERDATA::complete_semaphore, RASPISTILL_STATE::encoder_pool, PORT_USERDATA::file_handle, PORT_USERDATA::pstate, and vcos_log_error.

Referenced by main().

◆ main()

◆ mmal_status_to_int()

int mmal_status_to_int ( MMAL_STATUS_T  status)

Convert a MMAL status return value to a simple boolean of success ALso displays a fault if code is not success

Parameters
statusThe error code to convert
Returns
0 if status is sucess, 1 otherwise

Definition at line 758 of file RaspiCamControl.c.

Referenced by main().

◆ parse_cmdline()

static int parse_cmdline ( int  argc,
const char **  argv,
RASPISTILL_STATE state 
)
static

◆ signal_handler()

static void signal_handler ( int  signal_number)
static

Handler for sigint signals

Parameters
signal_numberID of incoming signal.

Definition at line 1143 of file RaspiStill.c.

References vcos_log_error.

Referenced by main().

◆ store_exif_tag()

static void store_exif_tag ( RASPISTILL_STATE state,
const char *  exif_tag 
)
static

Stores an EXIF tag in the state, incrementing various pointers as necessary. Any tags stored in this way will be added to the image file when add_exif_tags is called

Will not store if run out of storage space

Parameters
statePointer to state control struct
exif_tagEXIF tag string

Definition at line 1061 of file RaspiStill.c.

References RASPISTILL_STATE::exifTags, MAX_USER_EXIF_TAGS, and RASPISTILL_STATE::numExifTags.

Referenced by parse_cmdline().

Variable Documentation

◆ cmdline_commands

COMMAND_LIST cmdline_commands[]
static
Initial value:
=
{
{ 0 , "-help", "?", "This help information", 0 },
{ 1 , "-width", "w", "Set image width <size>", 1 },
{ 2 , "-height", "h", "Set image height <size>", 1 },
{ 3 , "-quality", "q", "Set jpeg quality <0 to 100>", 1 },
{ 4 , "-raw", "r", "Add raw bayer data to jpeg metadata", 0 },
{ 5 , "-output", "o", "Output filename <filename> (to write to stdout, use '-o -'). If not specified, no file is saved", 1 },
{ 14 , "-latest", "l", "Link latest complete image to filename <filename>", 1},
{ 6 , "-verbose", "v", "Output verbose information during run", 0 },
{ 7 , "-timeout", "t", "Time (in ms) before takes picture and shuts down (if not specified, set to 5s)", 1 },
{ 8 ,"-thumb", "th", "Set thumbnail parameters (x:y:quality)", 1},
{ 9 ,"-demo", "d", "Run a demo mode (cycle through range of camera options, no capture)", 0},
{ 10 ,"-encoding", "e", "Encoding to use for output file (jpg, bmp, gif, png)", 1},
{ 11 , "-exif", "x", "EXIF tag to apply to captures (format as 'key=value')", 1},
{ 12 ,"-timelapse", "tl", "Timelapse mode. Takes a picture every <t>ms", 1},
{ 13 ,"-fullpreview", "fp", "Run the preview using the still capture resolution (may reduce preview fps)", 0},
}

Definition at line 167 of file RaspiStill.c.

Referenced by display_valid_parameters(), and parse_cmdline().

◆ cmdline_commands_size

int cmdline_commands_size = sizeof(cmdline_commands) / sizeof(cmdline_commands[0])
static

Definition at line 186 of file RaspiStill.c.

Referenced by display_valid_parameters(), and parse_cmdline().

◆ encoding

MMAL_FOURCC_T encoding

◆ 

struct { ... } encoding_xref[]
Initial value:
=
{
{"jpg", MMAL_ENCODING_JPEG},
{"bmp", MMAL_ENCODING_BMP},
{"gif", MMAL_ENCODING_GIF},
{"png", MMAL_ENCODING_PNG}
}

Referenced by parse_cmdline().

◆ encoding_xref_size

int encoding_xref_size = sizeof(encoding_xref) / sizeof(encoding_xref[0])
static

Definition at line 200 of file RaspiStill.c.

Referenced by parse_cmdline().

◆ format

char* format

Definition at line 190 of file RaspiStill.c.

Referenced by _acquire_spdif(), _audio_stream_change_format(), _audio_stream_get_current_format(), _audio_stream_set_current_format(), avi_demux_handle_seek_push(), check_rate(), create_camera_component(), fill_gray(), fill_yuy2(), flv_demux_handle_seek_push(), gst_au_parse_handle_seek(), gst_au_parse_parse_header(), gst_au_parse_src_query(), gst_audio_amplify_process_function(), gst_audio_amplify_set_process_function(), gst_avi_demux_handle_seek(), gst_avi_demux_handle_src_query(), gst_avi_mux_audsink_set_caps(), gst_avi_mux_vidsink_set_caps(), gst_core_audio_asbd_to_caps(), gst_core_audio_initialize(), gst_core_audio_initialize_impl(), gst_core_audio_set_format(), gst_deinterlace_method_supported(), gst_deinterlace_method_supported_impl(), gst_deinterlace_set_method(), gst_deinterlace_simple_method_supported(), gst_deinterleave_add_new_pads(), gst_deinterleave_src_query(), gst_flv_demux_audio_negotiate(), gst_flv_demux_handle_seek_pull(), gst_flv_demux_handle_seek_push(), gst_flv_demux_query(), gst_flxdec_src_query_handler(), gst_image_freeze_src_event(), gst_image_freeze_src_query(), gst_image_sequence_src_query(), gst_index_entry_assoc_map(), gst_index_get_assoc_entry(), gst_index_get_assoc_entry_full(), gst_interleave_src_query(), gst_interleave_src_query_duration(), gst_matroska_demux_audio_caps(), gst_matroska_demux_handle_seek_event(), gst_matroska_demux_handle_seek_push(), gst_matroska_demux_query(), gst_matroska_demux_video_caps(), gst_matroska_mux_audio_pad_setcaps(), gst_matroska_parse_handle_seek_event(), gst_matroska_parse_handle_seek_push(), gst_matroska_parse_query(), gst_mem_index_get_assoc_entry(), gst_mem_index_index_format(), gst_multi_file_sink_post_message(), gst_multi_file_sink_post_message_from_time(), gst_multi_file_src_query(), gst_oss_helper_get_format_structure(), gst_oss_helper_rate_check_rate(), gst_osx_audio_ring_buffer_acquire(), gst_progress_report_do_query(), gst_progress_report_post_progress(), gst_progress_report_report(), gst_qt_mux_audio_sink_set_caps(), gst_qt_mux_map_format_to_flavor(), gst_qt_mux_map_format_to_header(), gst_qt_mux_register(), gst_qt_mux_subtitle_sink_set_caps(), gst_qt_mux_video_sink_set_caps(), gst_qtdemux_convert_seek(), gst_qtdemux_do_push_seek(), gst_qtdemux_do_seek(), gst_qtdemux_handle_src_query(), gst_rnd_buffer_size_src_event(), gst_rtp_vraw_depay_setcaps(), gst_rtp_vraw_pay_handle_buffer(), gst_rtspsrc_handle_internal_src_query(), gst_rtspsrc_handle_src_query(), gst_rtspsrc_perform_seek(), gst_scaletempo_query(), gst_scaletempo_set_caps(), gst_v4l2_memory_group_new(), gst_v4l2_object_acquire_format(), gst_v4l2_object_fill_format_list(), gst_v4l2_object_get_caps_helper(), gst_v4l2_object_get_caps_info(), gst_v4l2_object_match_buffer_layout(), gst_v4l2_object_probe_caps(), gst_v4l2_object_save_format(), gst_v4l2_object_set_format_full(), gst_v4l2_object_update_and_append(), gst_v4l2_object_v4l2fourcc_to_bare_struct(), gst_v4l2_object_v4l2fourcc_to_structure(), gst_v4l2_object_v4l2fourcc_to_video_format(), gst_v4l2sink_sync_overlay_fields(), gst_videomixer2_query_duration(), gst_videomixer2_src_query(), gst_waveform_sink_create_caps(), gst_wavparse_pad_query(), gst_wavparse_perform_seek(), gst_ximage_src_get_caps(), parse_cmdline(), qtdemux_audio_caps(), qtdemux_video_caps(), raspi_capture_set_format_and_start(), splitmux_src_pad_event(), and splitmux_src_pad_query().