Ardour  9.0-pre0-582-g084a23a80d
ffmpegfileimportable.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 Marijn Kruisselbrink <mek@google.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #ifndef _ardour_ffmpegfile_importable_source_h_
20 #define _ardour_ffmpegfile_importable_source_h_
21 
22 #include <atomic>
23 
24 #include "pbd/ringbuffer.h"
25 
28 #include "ardour/system_exec.h"
29 #include "ardour/types.h"
30 
31 namespace ARDOUR {
32 
34 {
35 public:
36  enum {
37  ALL_CHANNELS = -1,
38  };
39 
40  FFMPEGFileImportableSource (const std::string& path, int channel = ALL_CHANNELS);
41 
43 
44  /* ImportableSource API */
46  uint32_t channels () const { return _channels; }
47  samplecnt_t length () const { return _length; }
48  samplecnt_t samplerate () const { return _samplerate; }
49  void seek (samplepos_t pos);
50  samplepos_t natural_position () const { return _natural_position; }
51  bool clamped_at_unity () const { return false; }
52 
53  std::string format_name () const { return _format_name; }
54 
55 private:
56  void start_ffmpeg ();
57  void reset ();
58 
59  void did_read_data (std::string data, size_t size);
60 
61  std::string _path;
62  int _channel;
63 
64  uint32_t _channels;
68  std::string _format_name;
69 
71  /* Set to 1 to indicate that ffmpeg should be terminating. */
72  std::atomic<int> _ffmpeg_should_terminate;
73 
74  /* To make sure we don't try to parse partial floats, we might have a couple of bytes
75  * of leftover unparsable data after any `did_read_data` call. Those couple of bytes are
76  * stored here until the next `did_read_data` call.
77  */
78  std::string _leftover_data;
79 
81 
84 };
85 
86 } // namespace ARDOUR
87 
88 #endif /* _ardour_ffmpegfile_importable_source_h_ */
FFMPEGFileImportableSource(const std::string &path, int channel=ALL_CHANNELS)
void did_read_data(std::string data, size_t size)
samplecnt_t read(Sample *, samplecnt_t nframes)
#define LIBARDOUR_API
Temporal::samplecnt_t samplecnt_t
Temporal::samplepos_t samplepos_t