请用c++编写高并发多线程代码，要求：1.cpu竞争少，2.能供外部启停；3.能够高并发处理rtp over udp流的接收，解析，解码，编码
以下是一个基于C++的高并发多线程RTP over UDP流处理框架的示例代码。注意，此代码仅为示例，实际使用时需要根据具体的编解码器和RTP处理库进行相应修改。

#include <iostream>
#include <thread>
#include <atomic>
#include <vector>
#include <queue>
#include <mutex>
#include <condition_variable>
#include <chrono>
#include <arpa/inet.h>
#include <sys/socket.h>

// 用于RTP解析处理的库，根据实际项目选择
#include “RtpParser.h”
// 用于解码和编码的库，根据实际项目选择
#include “Decoder.h”
#include “Encoder.h”

const int MAX_RECEIVE_BUFFER_SIZE = 4096;

class ThreadPool {
public:
    ThreadPool(size_t threads): stop(false) {
        for (size_t i = 0; i < threads; ++i)
            workers.emplace_back([this] {
                while (!stop.load()) {
                    std::function<void()> task;
                    {
                        std::unique_lock<std::mutex> lock(queue_mutex);
                        condition.wait(lock, [this] { return stop.load() || !tasks.empty(); });
                        if (stop.load() && tasks.empty()) return;
                        task = std::move(tasks.front());
                        tasks.pop();
                    }
                    task();
                }
            });
    }

    void enqueue(std::function<void()> task) {
        {
            std::unique_lock<std::mutex> lock(queue_mutex);
            tasks.push(std::move(task));
        }
        condition.notify_one();
    }

    ~ThreadPool() {
        stop.store(true);
        condition.notify_all();
        for (std::thread &worker : workers)
            worker.join();
    }

private:
    std::vector<std::thread> workers;
    std::queue<std::function<void()>> tasks;
    std::mutex queue_mutex;
    std::condition_variable condition;
    std::atomic_bool stop;
};

class RTPHandler {
public:
    RTPHandler(int port, size_t thread_count)
        : thread_pool(thread_count), is_running(false) {
        sockfd = socket(AF_INET, SOCK_DGRAM, 0);
        sockaddr_in server_addr;
        server_addr.sin_family = AF_INET;
        server_addr.sin_port = htons(port);
        server_addr.sin_addr.s_addr = INADDR_ANY;

        if (bind(sockfd, (sockaddr *)&server_addr, sizeof(server_addr)) < 0) {
            std::cerr << “Socket bind failed.” << std::endl;
            exit(1);
        }
    }

    void start() {
        is_running.store(true);
        worker_thread = std::thread(&RTPHandler::receive_loop, this);
    }

    void stop() {
        is_running.store(false);
        worker_thread.join();
    }

private:
    void receive_loop() {
        char buffer[MAX_RECEIVE_BUFFER_SIZE];
        while (is_running.load()) {
            sockaddr_in client_addr;
            socklen_t client_len = sizeof(client_addr);
            int received_len = recvfrom(sockfd, buffer, MAX_RECEIVE_BUFFER_SIZE, 0,
                                        (sockaddr *)&client_addr, &client_len);
            if (received_len <= 0) {
                std::cerr << “Error receiving data.” << std::endl;
                continue;
            }

            thread_pool.enqueue(this, received_data = std::string(buffer, received_len) {
                // RTP解析
                RtpPacket rtp_packet = RtpParser::parse(received_data);
                // 解码
                DecodedFrame decoded_frame = Decoder::decode(rtp_packet);
                // 编码
                EncodedFrame encoded_frame = Encoder::encode(decoded_frame);
                // 发送RTP
                send_rtp(encoded_frame);
            });
        }
    }

    void send_rtp(const EncodedFrame &frame) {
        // 使用RTP处理库生成要发送的数据，根据实际项目选择
        RtpPacket packet = RtpParser::createPacket(frame);
        sockaddr_in dest_addr;
        // 设置目标地址和端口
        dest_addr.sin_family = AF_INET;
        dest_addr.sin_addr.s_addr = frame.destination_addr;
        dest_addr.sin_port = htons(frame.destination_port);

        sendto(sockfd, packet.data, packet.size, 0, (sockaddr *)&dest_addr, sizeof(dest_addr));
    }

    int sockfd;
    ThreadPool thread_pool;
    std::atomic_bool is_running;
    std::thread worker_thread;
};

int main() {
    int port = 12345;
    size_t thread_count = std::thread::hardware_concurrency(); // 使用并发线程的最大数

    RTPHandler rtp_handler(port, thread_count);
    rtp_handler.start();

    std::cout << “Press Enter to stop…” << std::endl;
    std::cin.get();

    rtp_handler.stop();
    return 0;
}

依据上面例子，修改：1.能够动态区分和选择是接收rtp over udp还是rtp over tcp的rtp流；2.要求一个端口起码能够处理100路rtp流，2.一路rtp流对应启一路send_rtp线程，并且能够控制send_rtp线程的启停以及资源销毁