static PyObject * clksyncmod_get_info(PyObject *self, PyObject *args) { clksync_info_t *nfo; if (!PyArg_ParseTuple(args, "")) { return NULL; } nfo = get_time_info(); PyObject *result = PyDict_New(); PyObject *ts = PyLong_FromUnsignedLongLong(nfo->ts); PyObject *tsckhz = PyLong_FromUnsignedLong(nfo->tsckhz); PyObject *tv_sec = PyLong_FromLong(nfo->time.tv_sec); PyObject *tv_nsec = PyLong_FromLong(nfo->time.tv_nsec); PyObject *shift = PyLong_FromUnsignedLong((unsigned long)nfo->shift); PyObject *mult = PyLong_FromUnsignedLong((unsigned long)nfo->mult); PyDict_SetItemString(result, "ts", ts); PyDict_SetItemString(result, "tsckhz", tsckhz); PyDict_SetItemString(result, "tv_sec", tv_sec); PyDict_SetItemString(result, "tv_nsec", tv_nsec); PyDict_SetItemString(result, "shift", shift); PyDict_SetItemString(result, "mult", mult); free(nfo); return result; }
void on_cli (evutil_socket_t fd, short what, void *arg) { if (NULL == arg) { fprintf (LOG_STREAM, "[ALARM] 'on_cli' has not get the" " valid argument\n") ; exit (1) ; } if (!(what & EV_WRITE)) { // The fd is not ready for writing goto _reloop ; } struct event *self = (struct event *)arg ; int ret, towrite ; time_info_t *ti ; char *pos ; if (NULL == (ti = get_time_info ())) { fprintf (LOG_STREAM, "[ERROR] Get time info failed\n") ; serv_exit () ; } for (ret=0, pos=ti->date, towrite=ti->len; towrite > 0; ) { errno = 0 ; ret = send (fd, pos, towrite, 0) ; #ifdef EWOULDBLOCK if (errno == EWOULDBLOCK || errno == EAGAIN) #else if (errno == EAGAIN) #endif break ; if (-1 == ret) { fprintf (LOG_STREAM, "[ERROR] Sending time information failed\n"); serv_exit () ; } towrite -= ret ; pos += ret ; } _reloop : if (-1 == event_del (self)) { fprintf (LOG_STREAM, "[ERROR] event_del in 'on_cli' failed\n") ; serv_exit () ; } if (-1 == event_add (self, NULL)) { } }
void log_time_state(struct logging_thread *log) { clksync_info_t *nfo = get_time_info(); /*printf("time_state_nfo\ntv_sec: %ld\n tv_nsec: %ld\n" "ts: %llu\ntsckhz: %u\n", nfo->time.tv_sec, nfo->time.tv_nsec, nfo->ts, nfo->tsckhz);*/ //FIXME: Why is this necessary? nfo->tsckhz = (unsigned int) nfo->tsckhz; // DSTRM_ADMIN_FAM/TIME_STATE log_admin_event(log, 12, 0, sizeof(*nfo), nfo); free(nfo); }
static int producer_get_image( mlt_frame frame, uint8_t** image, mlt_image_format* format, int* width, int* height, int writable ) { mlt_producer producer = mlt_frame_pop_service( frame ); mlt_frame bg_frame = NULL; mlt_frame text_frame = NULL; int error = 1; int size = 0; char* background = mlt_properties_get( MLT_PRODUCER_PROPERTIES( producer ), "background" ); time_info info; mlt_service_lock( MLT_PRODUCER_SERVICE( producer ) ); get_time_info( producer, frame, &info ); bg_frame = get_background_frame( producer ); if( !strcmp( background, "clock" ) ) { add_clock_to_frame( producer, bg_frame, &info ); } text_frame = get_text_frame( producer, &info ); add_text_to_bg( producer, bg_frame, text_frame ); if( bg_frame ) { // Get the image from the background frame. error = mlt_frame_get_image( bg_frame, image, format, width, height, writable ); size = mlt_image_format_size( *format, *width, *height, NULL ); // Detach the image from the bg_frame so it is not released. mlt_frame_set_image( bg_frame, *image, size, NULL ); // Attach the image to the input frame. mlt_frame_set_image( frame, *image, size, mlt_pool_release ); mlt_frame_close( bg_frame ); } if( text_frame ) { mlt_frame_close( text_frame ); } mlt_service_unlock( MLT_PRODUCER_SERVICE( producer ) ); return error; }
static int producer_get_audio( mlt_frame frame, int16_t** buffer, mlt_audio_format* format, int* frequency, int* channels, int* samples ) { mlt_producer producer = (mlt_producer)mlt_frame_pop_audio( frame ); mlt_properties producer_properties = MLT_PRODUCER_PROPERTIES( producer ); char* sound = mlt_properties_get( producer_properties, "sound" ); double fps = mlt_producer_get_fps( producer ); mlt_position position = mlt_frame_original_position( frame ); int size = 0; int do_beep = 0; time_info info; if( fps == 0 ) fps = 25; // Correct the returns if necessary *format = mlt_audio_float; *frequency = *frequency <= 0 ? 48000 : *frequency; *channels = *channels <= 0 ? 2 : *channels; *samples = *samples <= 0 ? mlt_sample_calculator( fps, *frequency, position ) : *samples; // Allocate the buffer size = *samples * *channels * sizeof( float ); *buffer = mlt_pool_alloc( size ); mlt_service_lock( MLT_PRODUCER_SERVICE( producer ) ); get_time_info( producer, frame, &info ); // Determine if this should be a tone or silence. if( strcmp( sound, "none") ) { if( !strcmp( sound, "2pop" ) ) { mlt_position out = mlt_properties_get_int( producer_properties, "out" ); mlt_position frames = out - position; if( frames == ( info.fps * 2 ) ) { do_beep = 1; } } else if( !strcmp( sound, "frame0" ) ) { if( info.frames == 0 ) { do_beep = 1; } } } if( do_beep ) { fill_beep( producer_properties, (float*)*buffer, *frequency, *channels, *samples ); } else { // Fill silence. memset( *buffer, 0, size ); } mlt_service_unlock( MLT_PRODUCER_SERVICE( producer ) ); // Set the buffer for destruction mlt_frame_set_audio( frame, *buffer, *format, size, mlt_pool_release ); return 0; }