Statistics
| Branch: | Revision:

janus-gateway / record.h @ becc0c84

History | View | Annotate | Download (3.64 KB)

1
/*! \file    record.h
2
 * \author   Lorenzo Miniero <lorenzo@meetecho.com>
3
 * \copyright GNU General Public License v3
4
 * \brief    Audio/Video recorder (headers)
5
 * \details  Implementation of a simple recorder utility that plugins
6
 * can make use of to record audio/video frames to a Janus file. This
7
 * file just saves RTP frames in a structured way, so that they can be
8
 * post-processed later on to get a valid container file (e.g., a .opus
9
 * file for Opus audio or a .webm file for VP8 video) and keep things
10
 * simpler on the plugin and core side.
11
 * \note If you want to record both audio and video, you'll have to use
12
 * two different recorders. Any muxing in the same container will have
13
 * to be done in the post-processing phase.
14
 * 
15
 * \ingroup core
16
 * \ref core
17
 */
18
 
19
#ifndef _JANUS_RECORD_H
20
#define _JANUS_RECORD_H
21

    
22
#include <inttypes.h>
23
#include <string.h>
24
#include <stdio.h>
25
#include <stdlib.h>
26

    
27
#include "mutex.h"
28

    
29

    
30
/*! \brief Media types we can record */
31
typedef enum janus_recorder_medium {
32
        JANUS_RECORDER_AUDIO,
33
        JANUS_RECORDER_VIDEO,
34
        JANUS_RECORDER_DATA
35
} janus_recorder_medium;
36

    
37
/*! \brief Structure that represents a recorder */
38
typedef struct janus_recorder {
39
        /*! \brief Absolute path to the directory where the recorder file is stored */ 
40
        char *dir;
41
        /*! \brief Filename of this recorder file */ 
42
        char *filename;
43
        /*! \brief Recording file */
44
        FILE *file;
45
        /*! \brief Codec the packets to record are encoded in ("vp8", "opus", "h264", "g711", "vp9") */
46
        char *codec;
47
        /*! \brief When the recording file has been created */
48
        gint64 created;
49
        /*! \brief Media this instance is recording */
50
        janus_recorder_medium type;
51
        /*! \brief Whether the info header for this recorder instance has already been written or not */
52
        int header:1;
53
        /*! \brief Whether this recorder instance can be used for writing or not */ 
54
        int writable:1;
55
        /*! \brief Mutex to lock/unlock this recorder instance */ 
56
        janus_mutex mutex;
57
} janus_recorder;
58

    
59
/*! \brief Initialize the recorder code
60
 * @param[in] tempnames Whether the filenames should have a temporary extension, while saving, or not
61
 * @param[in] extension Extension to add in case tempnames is true */
62
void janus_recorder_init(gboolean tempnames, const char *extension);
63
/*! \brief De-initialize the recorder code */
64
void janus_recorder_deinit(void);
65

    
66
/*! \brief Create a new recorder
67
 * \note If no target directory is provided, the current directory will be used. If no filename
68
 * is passed, a random filename will be used.
69
 * @param[in] dir Path of the directory to save the recording into (will try to create it if it doesn't exist)
70
 * @param[in] codec Codec the packets to record are encoded in ("vp8", "opus", "h264", "g711", "vp9")
71
 * @param[in] filename Filename to use for the recording
72
 * @returns A valid janus_recorder instance in case of success, NULL otherwise */
73
janus_recorder *janus_recorder_create(const char *dir, const char *codec, const char *filename);
74
/*! \brief Save an RTP frame in the recorder
75
 * @param[in] recorder The janus_recorder instance to save the frame to
76
 * @param[in] buffer The frame data to save
77
 * @param[in] length The frame data length
78
 * @returns 0 in case of success, a negative integer otherwise */
79
int janus_recorder_save_frame(janus_recorder *recorder, char *buffer, uint length);
80
/*! \brief Close the recorder
81
 * @param[in] recorder The janus_recorder instance to close
82
 * @returns 0 in case of success, a negative integer otherwise */
83
int janus_recorder_close(janus_recorder *recorder);
84
/*! \brief Free the recorder resources
85
 * @param[in] recorder The janus_recorder instance to free
86
 * @returns 0 in case of success, a negative integer otherwise */
87
int janus_recorder_free(janus_recorder *recorder);
88

    
89
#endif