ex

Fork of mbed-os-example-mbed5-blinky by mbed-os-examples

Committer:
TMBOY
Date:
Tue Jul 18 16:54:45 2017 +0800
Revision:
47:9e361da97763
?

Who changed what in which revision?

UserRevisionLine numberNew contents of line
TMBOY 47:9e361da97763 1 // Copyright 2017 Baidu Inc. All Rights Reserved.
TMBOY 47:9e361da97763 2 // Author: tai xiurong (taixiurong@baidu.com)
TMBOY 47:9e361da97763 3 //
TMBOY 47:9e361da97763 4 // Description:
TMBOY 47:9e361da97763 5
TMBOY 47:9e361da97763 6 #ifndef BAIDU_IOT_TINYDU_IOT_OS_SRC_RECORDER_BAIDU_OS_RECORDER_H
TMBOY 47:9e361da97763 7 #define BAIDU_IOT_TINYDU_IOT_OS_SRC_RECORDER_BAIDU_OS_RECORDER_H
TMBOY 47:9e361da97763 8
TMBOY 47:9e361da97763 9 #include <mbed.h>
TMBOY 47:9e361da97763 10
TMBOY 47:9e361da97763 11 #include "baidu_ca_adapter.h"
TMBOY 47:9e361da97763 12
TMBOY 47:9e361da97763 13 // #define O_BUFFER_LEN (800)
TMBOY 47:9e361da97763 14 // #define I_BUFFER_LEN ((O_BUFFER_LEN - 1) / 4 * 3)
TMBOY 47:9e361da97763 15
TMBOY 47:9e361da97763 16 //#define REC_LOG(_fmt, ...) //LOG("[REC]"_fmt, ##__VA_ARGS__)
TMBOY 47:9e361da97763 17
TMBOY 47:9e361da97763 18 namespace duer {
TMBOY 47:9e361da97763 19 static const unsigned int s_o_buffer_len = 800;
TMBOY 47:9e361da97763 20 static const unsigned int s_i_buffer_len = (s_o_buffer_len -1)/4 *3;
TMBOY 47:9e361da97763 21 class Recorder {
TMBOY 47:9e361da97763 22 public:
TMBOY 47:9e361da97763 23
TMBOY 47:9e361da97763 24 class IPlugin {
TMBOY 47:9e361da97763 25 public:
TMBOY 47:9e361da97763 26
TMBOY 47:9e361da97763 27 virtual int start_record() = 0;
TMBOY 47:9e361da97763 28
TMBOY 47:9e361da97763 29 virtual size_t read(void* data, size_t size) = 0;
TMBOY 47:9e361da97763 30
TMBOY 47:9e361da97763 31 virtual int stop_record() = 0;
TMBOY 47:9e361da97763 32
TMBOY 47:9e361da97763 33 virtual ~IPlugin() = 0;
TMBOY 47:9e361da97763 34
TMBOY 47:9e361da97763 35 };
TMBOY 47:9e361da97763 36
TMBOY 47:9e361da97763 37 class IListener {
TMBOY 47:9e361da97763 38 public:
TMBOY 47:9e361da97763 39
TMBOY 47:9e361da97763 40 virtual int on_start() = 0;
TMBOY 47:9e361da97763 41
TMBOY 47:9e361da97763 42 virtual int on_resume() = 0;
TMBOY 47:9e361da97763 43
TMBOY 47:9e361da97763 44 virtual int on_data(const void* data, size_t size) = 0;
TMBOY 47:9e361da97763 45
TMBOY 47:9e361da97763 46 virtual int on_pause() = 0;
TMBOY 47:9e361da97763 47
TMBOY 47:9e361da97763 48 virtual int on_stop() = 0;
TMBOY 47:9e361da97763 49
TMBOY 47:9e361da97763 50 virtual ~IListener() = 0;
TMBOY 47:9e361da97763 51
TMBOY 47:9e361da97763 52 };
TMBOY 47:9e361da97763 53
TMBOY 47:9e361da97763 54 class MiddleWare: public IListener {
TMBOY 47:9e361da97763 55 public:
TMBOY 47:9e361da97763 56
TMBOY 47:9e361da97763 57 MiddleWare();
TMBOY 47:9e361da97763 58
TMBOY 47:9e361da97763 59 virtual ~MiddleWare();
TMBOY 47:9e361da97763 60
TMBOY 47:9e361da97763 61 int set_listener(IListener* listener);
TMBOY 47:9e361da97763 62
TMBOY 47:9e361da97763 63 protected:
TMBOY 47:9e361da97763 64
TMBOY 47:9e361da97763 65 int process_start();
TMBOY 47:9e361da97763 66
TMBOY 47:9e361da97763 67 int process_resume();
TMBOY 47:9e361da97763 68
TMBOY 47:9e361da97763 69 int process_data(const void* data, size_t size);
TMBOY 47:9e361da97763 70
TMBOY 47:9e361da97763 71 int process_pause();
TMBOY 47:9e361da97763 72
TMBOY 47:9e361da97763 73 int process_stop();
TMBOY 47:9e361da97763 74
TMBOY 47:9e361da97763 75 private:
TMBOY 47:9e361da97763 76
TMBOY 47:9e361da97763 77 IListener* _listener;
TMBOY 47:9e361da97763 78 };
TMBOY 47:9e361da97763 79
TMBOY 47:9e361da97763 80 Recorder(IPlugin* plugin, size_t size, void* data);
TMBOY 47:9e361da97763 81 Recorder(IPlugin* plugin, size_t size);
TMBOY 47:9e361da97763 82 Recorder(IPlugin* plugin);
TMBOY 47:9e361da97763 83
TMBOY 47:9e361da97763 84 virtual ~Recorder();
TMBOY 47:9e361da97763 85
TMBOY 47:9e361da97763 86 int start();
TMBOY 47:9e361da97763 87
TMBOY 47:9e361da97763 88 int resume();
TMBOY 47:9e361da97763 89
TMBOY 47:9e361da97763 90 int pause();
TMBOY 47:9e361da97763 91
TMBOY 47:9e361da97763 92 int stop();
TMBOY 47:9e361da97763 93
TMBOY 47:9e361da97763 94 int set_listener(IListener* listener);
TMBOY 47:9e361da97763 95
TMBOY 47:9e361da97763 96 static void add_drop_invalid_record();
TMBOY 47:9e361da97763 97
TMBOY 47:9e361da97763 98 private:
TMBOY 47:9e361da97763 99 void run();
TMBOY 47:9e361da97763 100 IPlugin* _plugin;
TMBOY 47:9e361da97763 101 IListener* _listener;
TMBOY 47:9e361da97763 102 rtos::Thread _thread;
TMBOY 47:9e361da97763 103 int _state;
TMBOY 47:9e361da97763 104 size_t _capacity;
TMBOY 47:9e361da97763 105 void* _buff;
TMBOY 47:9e361da97763 106
TMBOY 47:9e361da97763 107 };
TMBOY 47:9e361da97763 108
TMBOY 47:9e361da97763 109 }//duer
TMBOY 47:9e361da97763 110
TMBOY 47:9e361da97763 111 #endif // BAIDU_IOT_TINYDU_IOT_OS_SRC_RECORDER_BAIDU_OS_RECORDER_H