File: FFmpegContext.h

package info (click to toggle)
freespace2 24.0.2%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: trixie
  • size: 43,188 kB
  • sloc: cpp: 583,107; ansic: 21,729; python: 1,174; sh: 464; makefile: 248; xml: 181
file content (67 lines) | stat: -rw-r--r-- 1,572 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#pragma once

#include "globalincs/vmallocator.h"
#include "globalincs/pstypes.h"
#include "cfile/cfile.h"

#include "FFmpeg.h"
#include "FFmpegHeaders.h"

#include <memory>

namespace libs {
namespace ffmpeg {

/**
 * @brief Stores a vector of bytes and an access position to treat it as file
 *
 *
 */

struct MemFileCursor {
    const SCP_vector<uint8_t> snddata;
    SCP_vector<uint8_t>::size_type cursor_pos;

    MemFileCursor(const uint8_t* snddata, size_t snd_len);
    MemFileCursor();
};


/**
 * @brief Contains a FFmpeg context
 *
 * This should be used for making sure a FFmpeg context is always deallocated even if an exception is throws.
 * createContext can be used for opening a specific file for FFmpeg decoding
 */


class FFmpegContext {
 private:
	AVFormatContext* m_ctx;
	CFILE* m_file;
	
    MemFileCursor m_memsound;

	FFmpegContext(CFILE* file);
	FFmpegContext(const uint8_t* snddata, size_t snd_len);

    void prepare(void *opaque,
                 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
                 int64_t (*seek)(void *opaque, int64_t offset, int whence));
 public:
	~FFmpegContext();

	FFmpegContext(const FFmpegContext&) = delete;
	FFmpegContext& operator=(const FFmpegContext&) = delete;

	inline AVFormatContext* ctx() { return m_ctx; }

	static std::unique_ptr<FFmpegContext> createContext(CFILE* mediaFile);
	
	static std::unique_ptr<FFmpegContext> createContextMem(const uint8_t* snddata, size_t snd_len);

	static std::unique_ptr<FFmpegContext> createContext(const SCP_string& path, int dir_type);
};

}
}