Error sending end packet

打开页面返回502 bad gateway,后台错误日志:

2011-11-21 18:23:14,276 [] WARN  core.MsgContext - Error sending end packet
java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
        at org.apache.jk.common.ChannelSocket.send(ChannelSocket.java:531)
        at org.apache.jk.common.JkInputStream.endMessage(JkInputStream.java:112)
        at org.apache.jk.core.MsgContext.action(MsgContext.java:293)
        at org.apache.coyote.Response.action(Response.java:182)
        at org.apache.coyote.Response.finish(Response.java:304)
        at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:204)
        at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:282)
        at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:767)
        at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:697)
        at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:889)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
        at java.lang.Thread.run(Thread.java:662)
2011-11-21 18:23:14,277 [] WARN  common.ChannelSocket - processCallbacks status 2

根据错误信息推测错误应该是mod_jk在send返回数据的时候,连接关掉了。

查了下apache和jboss的配置

apache:

Timeout 30

jboss:

 <Connector port="7011" address="${jboss.bind.address}" backlog="256" maxThreads="250" emptySessionPath="true" enableLookups="false" 
connectionTimeout="600000" disableUploadTimeout="true" protocol="AJP/1.3" URIEncoding="GBK"/>

如果服务器处理请求时间超过30s,则apache会关掉连接,后台处理好之后回写的时候,就报这个错误了。


查了一下该sql的查询时间,居然平均50多s,悲剧阿,优化sql去。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用FFmpeg实现RTMP推送音频流的C++代码示例: ```c++ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <stdint.h> #include <libavcodec/avcodec.h> #include <libavformat/avformat.h> #include <libavutil/avutil.h> #include <libavutil/opt.h> #include <libavutil/error.h> #include <libavutil/mathematics.h> #define AUDIO_INBUF_SIZE 20480 #define AUDIO_REFILL_THRESH 4096 int main(int argc, char **argv) { AVOutputFormat *ofmt = NULL; AVFormatContext *ifmt_ctx = NULL, *ofmt_ctx = NULL; AVPacket pkt; AVCodecContext *dec_ctx = NULL, *enc_ctx = NULL; AVCodec *encoder = NULL; int stream_index = 0; int ret = 0; int64_t cur_pts = 0; uint8_t inbuf[AUDIO_INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE]; uint8_t *data = NULL; int data_size = 0; const char *out_filename = "rtmp://localhost:1935/live/stream"; const char *in_filename = "test.mp3"; av_register_all(); // Open input file context if ((ret = avformat_open_input(&ifmt_ctx, in_filename, NULL, NULL)) < 0) { av_log(NULL, AV_LOG_ERROR, "Cannot open input file\n"); goto end; } // Retrieve stream information if ((ret = avformat_find_stream_info(ifmt_ctx, NULL)) < 0) { av_log(NULL, AV_LOG_ERROR, "Cannot find stream information\n"); goto end; } // Dump input information av_dump_format(ifmt_ctx, 0, in_filename, 0); // Open output file context if ((ret = avformat_alloc_output_context2(&ofmt_ctx, NULL, "flv", out_filename)) < 0) { av_log(NULL, AV_LOG_ERROR, "Cannot create output context\n"); goto end; } ofmt = ofmt_ctx->oformat; // Add audio stream to output context for (int i = 0; i < ifmt_ctx->nb_streams; i++) { if (ifmt_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { AVStream *in_stream = ifmt_ctx->streams[i]; dec_ctx = avcodec_alloc_context3(NULL); if (!dec_ctx) { av_log(NULL, AV_LOG_ERROR, "Failed to allocate decoder context\n"); goto end; } ret = avcodec_parameters_to_context(dec_ctx, in_stream->codecpar); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Failed to copy decoder parameters to input decoder context\n"); goto end; } encoder = avcodec_find_encoder(AV_CODEC_ID_AAC); if (!encoder) { av_log(NULL, AV_LOG_ERROR, "Codec not found\n"); goto end; } enc_ctx = avcodec_alloc_context3(encoder); if (!enc_ctx) { av_log(NULL, AV_LOG_ERROR, "Failed to allocate encoder context\n"); goto end; } enc_ctx->channels = dec_ctx->channels; enc_ctx->channel_layout = dec_ctx->channel_layout; enc_ctx->sample_rate = dec_ctx->sample_rate; enc_ctx->sample_fmt = encoder->sample_fmts[0]; enc_ctx->bit_rate = 128000; if (ofmt->flags & AVFMT_GLOBALHEADER) { enc_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; } ret = avcodec_open2(enc_ctx, encoder, NULL); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Failed to open encoder\n"); goto end; } AVStream *out_stream = avformat_new_stream(ofmt_ctx, encoder); if (!out_stream) { av_log(NULL, AV_LOG_ERROR, "Failed to allocate output stream\n"); goto end; } ret = avcodec_parameters_copy(out_stream->codecpar, enc_ctx->codecpar); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Failed to copy encoder parameters to output stream\n"); goto end; } out_stream->codecpar->codec_tag = 0; if (ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER) { out_stream->codecpar->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; } stream_index = out_stream->index; break; } } // Dump output information av_dump_format(ofmt_ctx, 0, out_filename, 1); // Open output file if (!(ofmt->flags & AVFMT_NOFILE)) { ret = avio_open(&ofmt_ctx->pb, out_filename, AVIO_FLAG_WRITE); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Cannot open output file\n"); goto end; } } // Write header to output file ret = avformat_write_header(ofmt_ctx, NULL); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Error occurred when opening output file\n"); goto end; } // Read frames from input file and write to output file while (1) { AVStream *in_stream, *out_stream; // Read packet from input file ret = av_read_frame(ifmt_ctx, &pkt); if (ret < 0) { break; } // Ignore packets that do not belong to the audio stream if (pkt.stream_index != stream_index) { av_packet_unref(&pkt); continue; } in_stream = ifmt_ctx->streams[pkt.stream_index]; out_stream = ofmt_ctx->streams[pkt.stream_index]; // Calculate packet duration AVRational time_base = in_stream->time_base; int64_t pts_time = av_rescale_q(pkt.pts, time_base, AV_TIME_BASE_Q); int64_t now_time = av_gettime() - cur_pts; if (now_time < pts_time) { av_usleep(pts_time - now_time); } // Decode audio frame ret = avcodec_send_packet(dec_ctx, &pkt); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Error sending packet to decoder\n"); goto end; } while (ret >= 0) { AVFrame *decoded_frame = av_frame_alloc(); if (!decoded_frame) { av_log(NULL, AV_LOG_ERROR, "Failed to allocate memory for decoded frame\n"); goto end; } ret = avcodec_receive_frame(dec_ctx, decoded_frame); if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) { av_frame_free(&decoded_frame); break; } else if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Error receiving frame from decoder\n"); goto end; } // Encode audio frame AVPacket enc_pkt; av_init_packet(&enc_pkt); enc_pkt.data = NULL; enc_pkt.size = 0; ret = avcodec_send_frame(enc_ctx, decoded_frame); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Error sending frame to encoder\n"); goto end; } while (ret >= 0) { ret = avcodec_receive_packet(enc_ctx, &enc_pkt); if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) { break; } else if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Error receiving packet from encoder\n"); goto end; } // Write packet to output file av_packet_rescale_ts(&enc_pkt, enc_ctx->time_base, out_stream->time_base); enc_pkt.stream_index = stream_index; ret = av_write_frame(ofmt_ctx, &enc_pkt); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Error writing audio frame\n"); goto end; } av_packet_unref(&enc_pkt); } av_frame_free(&decoded_frame); } av_packet_unref(&pkt); } // Flush encoders ret = avcodec_send_frame(enc_ctx, NULL); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Error sending null frame to encoder\n"); goto end; } while (ret >= 0) { AVPacket enc_pkt; av_init_packet(&enc_pkt); enc_pkt.data = NULL; enc_pkt.size = 0; ret = avcodec_receive_packet(enc_ctx, &enc_pkt); if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) { break; } else if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Error receiving packet from encoder\n"); goto end; } av_packet_rescale_ts(&enc_pkt, enc_ctx->time_base, ofmt_ctx->streams[stream_index]->time_base); enc_pkt.stream_index = stream_index; ret = av_write_frame(ofmt_ctx, &enc_pkt); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Error writing audio frame\n"); goto end; } av_packet_unref(&enc_pkt); } // Write trailer to output file av_write_trailer(ofmt_ctx); end: avcodec_free_context(&dec_ctx); avcodec_free_context(&enc_ctx); avformat_close_input(&ifmt_ctx); if (ofmt_ctx && !(ofmt->flags & AVFMT_NOFILE)) { avio_closep(&ofmt_ctx->pb); } avformat_free_context(ofmt_ctx); if (ret < 0) { char errbuf[AV_ERROR_MAX_STRING_SIZE] = {0}; av_strerror(ret, errbuf, sizeof(errbuf)); av_log(NULL, AV_LOG_ERROR, "Error occurred: %s\n", errbuf); return 1; } return 0; } ``` 这段代码假设输入文件为MP3格式,输出文件为FLV格式,并且只包含一个音频流。代码将音频流从输入文件中解码,并使用AAC编码器编码成AAC格式,然后将编码后的音频流写入输出文件。在实际使用时,你需要根据你的需求进行相应的修改。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值