User:Thinker/GenericBuffering: Difference between revisions
| Line 19: | Line 19: | ||
QMT_RED // Random early drop | QMT_RED // Random early drop | ||
}; | }; | ||
union QueueDisciplineType { | union QueueDisciplineType { QDT_FIFO, QDT_LIFO, QDT_PRIO }; | ||
union BufferSyncType { | union BufferSyncType { BST_NONE, BST_ACK, BST_NAK }; | ||
union QueueThreadingType { | union QueueThreadingType { | ||
QTT_NONE, // This queue does not create any thread | |||
QTT_THREAD_BEGIN, // This queue is a begin of a new thread (input buffers are passed from other threads) | |||
QTT_PROC_BEGIN // This queue is a begin of a process (input buffers are passed from other processes; for ex., content process) | |||
}; | }; | ||
union BufferManagementType { | union BufferManagementType { | ||
BMT_REUSE, // This queue reuse buffers from the up streams. | BMT_REUSE, // This queue reuse buffers from the up streams. | ||
BMT_UPSTREAM, // This queue requests new buffers from a up stream. | |||
BMT_DOWNSTREAM, // This queue requests new buffers from a down stream. | |||
BMT_PROVIDER // This queue provide new buffers. | |||
}; | }; | ||
class BufferService { | class BufferService { | ||
Revision as of 09:58, 25 June 2013
A lot of features in Gecko require some kind of buffering; for ex., Camera, media playing back, WebRTC, Animation, ... etc. But, there is no generic buffering framework in Gecko. Every module implements its-owned buffering. The pro is getting better performance due to fully customized for the task. The cons are hardly for adapting, studying, analyzing, and porting. So, we need a framework for buffering that is easy to customize for performance, adapt to different configurations and applications, easily analysis it, port to various platforms, and a common language/slang among modules.
Buffering
There are several factors should be considered for buffering/queuing.
- queue size
- queue management
- queuing discipline
- buffer synchronization
- ack
- nak
- threading
- servers
- the service function
- the number of servers
- Buffer management
union QueueManagementType {
QMT_DEFAULT, // Tail drop if this queue is full
QMT_RED // Random early drop
};
union QueueDisciplineType { QDT_FIFO, QDT_LIFO, QDT_PRIO };
union BufferSyncType { BST_NONE, BST_ACK, BST_NAK };
union QueueThreadingType {
QTT_NONE, // This queue does not create any thread
QTT_THREAD_BEGIN, // This queue is a begin of a new thread (input buffers are passed from other threads)
QTT_PROC_BEGIN // This queue is a begin of a process (input buffers are passed from other processes; for ex., content process)
};
union BufferManagementType {
BMT_REUSE, // This queue reuse buffers from the up streams.
BMT_UPSTREAM, // This queue requests new buffers from a up stream.
BMT_DOWNSTREAM, // This queue requests new buffers from a down stream.
BMT_PROVIDER // This queue provide new buffers.
};
class BufferService {
virtual serve(Buffer *buf) = 0;
};
class BufferCreator {
virtual Buffer *createBuffer(int payload_size) = 0;
};
typedef BufferService *(*BufServiceFactory)(Queue *queue);
typedef BufferCreator *(*BufferCreatorFactory)(Queue *queue);
struct QueueConfig {
const char *qname;
int qsize;
QueueManagementType qman;
QueueDisciplineType qdisc;
BufferSyncType bsync;
QueueThreadingType qthreading;
BufferManagementType bman; // this type must match the behavior of the servicefunc
BufferCreatorFactory *bcreatorfactory; // valid only for bman == MST_PROVIDER
BufServiceFactory *bservicefactory;
int numOutPads; // Output pads
};
struct QueueHandlers {
QueueManager *qman;
QueueDiscipline *qdisc;
BufferManager *bman;
BufferCreator *bcreator;
BufferService *bservice;
};
struct Queue {
QueueConfig *config;
QueueHandlers *handlers;
list<Buffer*> buffers;
};
typedef int (*BufferReleaseFunc)(Buffer *buf);
struct Buffer {
Queue *creator;
BufferReleaseFunc releasefunc;
BufferPayloadType bufferType;
int payloadSize;
void *payload; // payload can be separated from Buffer itself, so we can apply Buffer to GL buffers...,etc.
};
Configuration of Queues
Create and connect queues together. With info. from QueueConfig, it is possible to separate pipe optimization from buffer processing; e.g. the service function in QueueConfig. Service functions are responsible for processing input buffers of a queue and generate output buffers; for ex., a decoder or a mixer.
Pipeline optimizations are about buffering reusing, buffer passing, synchronization, ..., etc. They should be extracted from the code of processors. By implement various types of buffer management, synchronization, buffer passing mechanisms, developer can try different combinations of mechanisms during configuration stage to get better performance. For example, use RED or tail drop, a separated threading or without new thread, GL buffers or normal buffers, ... etc. These features can be decided during configuration stage of a stream pipeline. So, we can try different combinations very easily.
Use case
Requirements
- Statistic
- Memory size/queue size
- Export statistic data for developer to figure out memory or performance bottleneck