<commit_before>//
//  protocol_rtmp.c
//  cpili
//
//  Created by 0dayZh on 15/9/16.
//  Copyright (c) 2015年 pili-engineering. All rights reserved.
//

#include "protocol_rtmp.h"

#include <stdio.h>

static void stream_cb(uint8_t state) {
    printf("stream state: %d\n", state);
}

bool rtmp_open(cpili_url_context_t *ctx, const char *url) {
    pili_stream_context_p stream_ctx = pili_create_stream_context();
    pili_init_stream_context(stream_ctx, 0, 0, stream_cb);
    
    rtmp_user_data_t user_data = {stream_ctx, {NULL, NULL}};
    ctx->user_data = &user_data;
    
    bool result = !!pili_stream_push_open(stream_ctx, url);
    if (result) {
        pili_release_stream_context(stream_ctx);
        ctx->user_data = NULL;
        user_data.stream_ctx = NULL;
        puts("Fail to open rtmp stream");
    }
    
    return result;
}

bool rtmp_read(cpili_url_context_t *ctx, unsigned char *buf, int size) {
    // do nothing
    return false;
}

bool rtmp_write(cpili_url_context_t *ctx, const unsigned char *buf, int size) {
    pili_stream_context_p stream_ctx = ((rtmp_user_data_t *)ctx->user_data)->stream_ctx;
    
    flv_tag_p flv_tag = (flv_tag_p)buf;
    bool result = pili_write_packet(stream_ctx, flv_tag);
    
    return result;
}

bool rtmp_close(cpili_url_context_t *ctx) {
    bool result = true;
    return result;
}<commit_msg>Update protocol rtmp<commit_after>//
//  protocol_rtmp.c
//  cpili
//
//  Created by 0dayZh on 15/9/16.
//  Copyright (c) 2015年 pili-engineering. All rights reserved.
//

#include "protocol_rtmp.h"

#include <stdio.h>

static void stream_cb(uint8_t state, pili_error_t error) {
    printf("stream state: %d\n", state);
}

bool rtmp_open(cpili_url_context_t *ctx, const char *url) {
    pili_stream_context_p stream_ctx = pili_create_stream_context();
    pili_init_stream_context(stream_ctx, 0, 0, stream_cb);
    
    rtmp_user_data_t user_data = {stream_ctx, {NULL, NULL}};
    ctx->user_data = &user_data;
    
    bool result = !!pili_stream_push_open(stream_ctx, url);
    if (result) {
        pili_release_stream_context(stream_ctx);
        ctx->user_data = NULL;
        user_data.stream_ctx = NULL;
        puts("Fail to open rtmp stream");
    }
    
    return result;
}

bool rtmp_read(cpili_url_context_t *ctx, unsigned char *buf, int size) {
    // do nothing
    return false;
}

bool rtmp_write(cpili_url_context_t *ctx, const unsigned char *buf, int size) {
    pili_stream_context_p stream_ctx = ((rtmp_user_data_t *)ctx->user_data)->stream_ctx;
    
    flv_tag_p flv_tag = (flv_tag_p)buf;
    bool result = pili_write_flv_tag(stream_ctx, flv_tag);
    
    return result;
}

bool rtmp_close(cpili_url_context_t *ctx) {
    bool result = true;
    return result;
}
{'fraction_non_alphanumeric': 0.11131386861313869, 'fraction_numerical': 0.00948905109489051, 'mean_word_length': 3.5008210180623975, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7178840', 'n_tokens_mistral': 1051, 'n_tokens_neox': 1027, 'n_words': 218}