]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add switch_core_file_write_video
authorSeven Du <dujinfang@gmail.com>
Fri, 20 Jul 2012 03:38:20 +0000 (11:38 +0800)
committerSeven Du <dujinfang@gmail.com>
Fri, 20 Jul 2012 03:38:20 +0000 (11:38 +0800)
open a door to write video data
so it is possible to record a .fsv file
also possible to write to .mp4 with proper file format support

src/include/switch_core.h
src/include/switch_module_interfaces.h
src/mod/applications/mod_fsv/mod_fsv.c
src/switch_core_file.c

index ae7e62153918e01bfac7ef42aeb0b49b874599f3..f37280f3e79c0d25843e4f472903a742be4aa867 100644 (file)
@@ -1648,6 +1648,15 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_read(_In_ switch_file_handle_t
 SWITCH_DECLARE(switch_status_t) switch_core_file_write(_In_ switch_file_handle_t *fh, void *data, switch_size_t *len);
 
 /*! 
+  \brief Write media to a file handle
+  \param fh the file handle to write to
+  \param data the buffer to write
+  \param len the amount of data to write from the buffer
+  \return SWITCH_STATUS_SUCCESS with len adjusted to the bytes written if successful
+*/
+SWITCH_DECLARE(switch_status_t) switch_core_file_write_video(_In_ switch_file_handle_t *fh, void *data, switch_size_t *len);
+
+/*!
   \brief Seek a position in a file
   \param fh the file handle to seek
   \param cur_pos the current position in the file
index af85e3ed7c1653cb35867823902345c7058ef342..7e024530c535c4bff6af231ba55fb3311faf75e7 100644 (file)
@@ -273,6 +273,10 @@ struct switch_file_interface {
        /*! function to write from the file */
        switch_status_t (*file_write) (switch_file_handle_t *, void *data, switch_size_t *len);
        /*! function to seek to a certian position in the file */
+       switch_status_t (*file_read_video) (switch_file_handle_t *, void *data, switch_size_t *len);
+       /*! function to write from the file */
+       switch_status_t (*file_write_video) (switch_file_handle_t *, void *data, switch_size_t *len);
+       /*! function to seek to a certian position in the file */
        switch_status_t (*file_seek) (switch_file_handle_t *, unsigned int *cur_pos, int64_t samples, int whence);
        /*! function to set meta data */
        switch_status_t (*file_set_string) (switch_file_handle_t *fh, switch_audio_col_t col, const char *string);
index e3c47cfe768da0b929f9cd82207df16579cfebdd..01160f6f7f12c35604cca8d95603fed6e63af6ee 100644 (file)
@@ -703,30 +703,30 @@ static switch_status_t fsv_file_write(switch_file_handle_t *handle, void *data,
        return status;
 }
 
-// static switch_status_t fsv_file_write_video(switch_file_handle_t *handle, void *data, size_t *len)
-// {
-//     uint32_t datalen = *len;
-//     uint32_t bytes = datalen | VID_BIT;
-//     size_t size;
-//     switch_status_t status = SWITCH_STATUS_SUCCESS;
+static switch_status_t fsv_file_write_video(switch_file_handle_t *handle, void *data, size_t *len)
+{
+       uint32_t datalen = *len;
+       uint32_t bytes = datalen | VID_BIT;
+       size_t size;
+       switch_status_t status = SWITCH_STATUS_SUCCESS;
 
-//     fsv_file_context *context = handle->private_info;
-//     /* switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "writing: %ld\n", (long)(*len)); */
+       fsv_file_context *context = handle->private_info;
+       /* switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "writing: %ld\n", (long)(*len)); */
 
-//     switch_mutex_lock(context->mutex);
+       switch_mutex_lock(context->mutex);
 
-//     size = sizeof(bytes);
-//     if (switch_file_write(context->fd, &bytes, &size) != SWITCH_STATUS_SUCCESS) {
-//             switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "write error\n");
-//             return SWITCH_STATUS_FALSE;
-//     }
+       size = sizeof(bytes);
+       if (switch_file_write(context->fd, &bytes, &size) != SWITCH_STATUS_SUCCESS) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "write error\n");
+               return SWITCH_STATUS_FALSE;
+       }
 
-//     *len = datalen;
-//     status =  switch_file_write(context->fd, data, len);
-//     switch_mutex_unlock(context->mutex);
+       *len = datalen;
+       status =  switch_file_write(context->fd, data, len);
+       switch_mutex_unlock(context->mutex);
 
-//     return status;
-// }
+       return status;
+}
 
 static switch_status_t fsv_file_set_string(switch_file_handle_t *handle, switch_audio_col_t col, const char *string)
 {
@@ -760,7 +760,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_fsv_load)
        file_interface->file_truncate = fsv_file_truncate;
        file_interface->file_read = fsv_file_read;
        file_interface->file_write = fsv_file_write;
-       // file_interface->file_write_video = fsv_file_write_video;
+       file_interface->file_write_video = fsv_file_write_video;
        file_interface->file_seek = fsv_file_seek;
        file_interface->file_set_string = fsv_file_set_string;
        file_interface->file_get_string = fsv_file_get_string;
index ed1a03f76bfabf7d7b8155f67df08c35ab2c51ce..b1a1effc852678b9a4584f9523b83bd7f8d7b6c4 100644 (file)
@@ -406,6 +406,23 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_write(switch_file_handle_t *fh,
        }
 }
 
+SWITCH_DECLARE(switch_status_t) switch_core_file_write_video(switch_file_handle_t *fh, void *data, switch_size_t *len)
+{
+       switch_assert(fh != NULL);
+       switch_assert(fh->file_interface != NULL);
+
+       if (!switch_test_flag(fh, SWITCH_FILE_OPEN)) {
+               return SWITCH_STATUS_GENERR;
+       }
+
+       if (!fh->file_interface->file_write_video) {
+               return SWITCH_STATUS_FALSE;
+       }
+
+       return fh->file_interface->file_write_video(fh, data, len);
+
+}
+
 SWITCH_DECLARE(switch_status_t) switch_core_file_seek(switch_file_handle_t *fh, unsigned int *cur_pos, int64_t samples, int whence)
 {
        switch_status_t status;